Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCurrentPageChanged with ID and index #251

Open
blingkonnerth opened this issue Jul 3, 2024 · 6 comments
Open

onCurrentPageChanged with ID and index #251

blingkonnerth opened this issue Jul 3, 2024 · 6 comments
Labels
enhancement New feature or request Sheet Page as Widget Issues will be answered under this theme

Comments

@blingkonnerth
Copy link

I would love have a onPageChanged - Callback.

I would expect it to look something like this:

onCurrentPageChanged: (newPageId, index) {
// ... do some stuff here
}

This came up when I wanted to build in tracking for the bottomsheet. I had this method before:

  static void _handleTracking({
    required BuildContext context,
    required List<UIBottomSheetPageModel> pages,
    required int currentIndex,
    required ValueNotifier<int> pageIndexNotifier,
  }) {
    // Since the views inside the bottom sheet are not actual routes,
    // we need to track the navigation manually.

    final firstPage = pages[0];

    // Track initial page
    context.appDelegate.trackNavigation(
      navigationType: UINavigationType.push,
      routeName: firstPage.trackingName,
      trackWithSegment: true,
    );

    // Track navigation inside the modal sheet
    pageIndexNotifier.addListener(() {
      final newIndex = pageIndexNotifier.value;
      final newPage = pages[newIndex];

      context.appDelegate.trackNavigation(
        navigationType: newIndex > currentIndex
            ? UINavigationType.push
            : UINavigationType.pop,
        routeName: newPage.trackingName,
        trackWithSegment: true,
      );
      currentIndex = newIndex;
    });
  }

But this will obviously not work when dealing with dynamic routes or even when pushing or popping. It will only work if all pages are constant.

I guess I could get hacky here and still manage to make it work, but everything would be solved, by a simply onCurrentPageChanged - callback (getting the id of the new page and index would be crucial here).

@blingkonnerth blingkonnerth added the enhancement New feature or request label Jul 3, 2024
@ulusoyca
Copy link
Collaborator

ulusoyca commented Jul 4, 2024

Brilliant idea. Would you consider opening a PR?

@blingkonnerth
Copy link
Author

I wish I could, but I don't quite understand where exactly I have to call it .. I will give it another try later this week.

@blingkonnerth
Copy link
Author

@ulusoyca I looked into it but wasn't able to get it properly done. When looking into it, I think instead of just passing the id, passing the whole page would be even better for more flexibility?

@ulusoyca ulusoyca added the Sheet Page as Widget Issues will be answered under this theme label Jul 18, 2024
@ulusoyca
Copy link
Collaborator

ulusoyca commented Jul 18, 2024

@MbIXjkee is currently managing the work that will add internal navigation system to the modal. Adding a navigation observer will solve this. Expected to be released in the 0.8.x.

@blingkonnerth
Copy link
Author

"interntal navigation observer" sounds perfect! @MbIXjkee 🫶

@ulusoyca
Copy link
Collaborator

Correction: It is a long work and expected in 0.9.x #271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Sheet Page as Widget Issues will be answered under this theme
Projects
None yet
Development

No branches or pull requests

2 participants