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

路由到Fragment是否可以用非回调式? #27

Closed
anymao opened this issue Jan 13, 2022 · 1 comment
Closed

路由到Fragment是否可以用非回调式? #27

anymao opened this issue Jan 13, 2022 · 1 comment

Comments

@anymao
Copy link

anymao commented Jan 13, 2022

看了wiki示例,对于路由到Fragment这节:
https://github.com/didi/DRouter/wiki/1.-Router#fragment%E5%AF%BC%E8%88%AA
是否存在同步式路由带Fragment的调用方式?类似于
Fragment f = DRouter.build("didi://router/message").start();

在像ViewPager+DRouter这种场景的时候,需要获取到多个Fragment再设置到Adapter中,会有这种需求。

tks!

@weigao123
Copy link
Collaborator

我会重新考虑一下,不过目前有同步方式获取到Fragment,参考以下

protected @NonNull Fragment newFragment(String uri) {
    final Fragment[] fragments = {null};
    DRouter.build(uri).start(null, new RouterCallback() {
        @Override
        public void onResult(@NonNull Result result) {
            fragments[0] = result.getFragment();
        }
    });
    if (fragments[0] == null) {
        return new EmptyFragment();
    }
    return fragments[0];
}

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

No branches or pull requests

2 participants