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

feat: support pause kraken pages when navigator changes. #877

Merged
merged 11 commits into from
Dec 16, 2021

Conversation

andycall
Copy link
Member

@andycall andycall commented Nov 15, 2021

支持通过 Flutter 提供的 RouteObserver 监听页面的跳转状态。如果页面被跳转到新页面,timer 和 requestAnimationCallback 会被暂停,其他状态都会被保留。当页面再次返回时,恢复先前的回调和状态。

// Register the RouteObserver as a navigation observer.
final RouteObserver<ModalRoute<void>> routeObserver = RouteObserver<ModalRoute<void>>();

void main() {
  KrakenWebsocket.initialize();

  runApp(MaterialApp(
    home: MyApp(),
    navigatorObservers: [routeObserver],
  ));
}


class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Second Route'),
      ),
      body: Center(
        child: Column(children: [
          Kraken(
            bundlePath: 'https://kraken.oss-cn-hangzhou.aliyuncs.com/demo/feeds-demo.js', 
            viewportHeight: 200, 
            routeObserver: routeObserver
          ),
      ),
    );
  }
}

kraken/lib/widget.dart Outdated Show resolved Hide resolved
kraken/lib/widget.dart Outdated Show resolved Hide resolved
wssgcg1213
wssgcg1213 previously approved these changes Nov 23, 2021
@andycall
Copy link
Member Author

LGTM

@yuanyan yuanyan self-requested a review November 23, 2021 14:44
yuanyan
yuanyan previously approved these changes Nov 23, 2021
yuanyan
yuanyan previously approved these changes Dec 6, 2021
Copy link
Member

@wssgcg1213 wssgcg1213 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@yuanyan yuanyan merged commit 81ec6eb into main Dec 16, 2021
@yuanyan yuanyan deleted the feat/navigation_observer branch December 16, 2021 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants