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时候的问题 #473

Closed
Gundam0079 opened this issue Aug 1, 2017 · 11 comments
Closed

同时打开打开多个fragment时候的问题 #473

Gundam0079 opened this issue Aug 1, 2017 · 11 comments
Labels

Comments

@Gundam0079
Copy link

用start方法同时打开多个fragment 会遇到栈顺序不对的问题
定位到FragmentationDelegate 的start方法 由于事务的问题
尝试同时调用 bindContainerId和 ft.add ft.addToBackStack最后执行supportCommit(fragmentManager, ft);貌似还是不对

需求是这样的有时候页面路由 会有同时打开多个页的需求 试过用延时200毫秒逐个执行start方法是可以的
但是中间会呈现出一页页跳转的效果不太理想
所以想请大神提供一个打开fragmentList的方法么

@Gundam0079
Copy link
Author

这么写貌似有很多问题 请大神指点应该怎么写
void start(FragmentManager fragmentManager, SupportFragment from, List toList, ArrayList<TransactionRecord.SharedElement> sharedElementList) {
FragmentTransaction ft = fragmentManager.beginTransaction();

    if (sharedElementList == null) {
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    } else {
        for (TransactionRecord.SharedElement item : sharedElementList) {
            ft.addSharedElement(item.sharedElement, item.sharedName);
        }
    }

    for (int i = 0; i < toList.size(); i++) {

        ft.add(from.getContainerId(), toList.get(i), toList.get(i).getTag());
        if(i == 0){
            if (from.getTag() != null) {
                ft.hide(from);
            }
        }else{
            ft.hide(toList.get(i-1));
        }
        ft.addToBackStack(toList.get(i).getTag());

    }

    supportCommit(fragmentManager, ft);
}

@YoKeyword
Copy link
Owner

@Gundam0079 提供下 库版本,support包版本

同时多次start() 是允许的,你的栈视图顺序不对是怎么表现的?

@Gundam0079
Copy link
Author

多次start以后 回退到root 然后再次start多个 点开红球 栈的顺序是不对的
比如 顺序启动ABCD 然后回退到A 再启动 顺序就变成红球的顺序是ADBC 回退的时候 打印生命周期方法也是不太对

@Gundam0079
Copy link
Author

其实就是一个实验 start同时打开ABCD四个页面 回退到A
再次start同时打开ABCD 看顺序 打印生命周期方法的顺序

@YoKeyword
Copy link
Owner

版本?

@Gundam0079
Copy link
Author

1.0.7

@YoKeyword
Copy link
Owner

使用v1.0.9试试看, v1.0.9对commit机制优化了

@Gundam0079
Copy link
Author

我分析是
@OverRide
public void start(SupportFragment toFragment, @SupportFragment.LaunchMode int launchMode) {
mFragmentationDelegate.dispatchStartTransaction(getSupportFragmentManager(), getTopFragment(), toFragment, 0, launchMode, FragmentationDelegate.TYPE_ADD);
}

这个方法如果同时调用 getTopFragment()获取的应该会有问题 fragment事务还没执行完

好的 我用 1.0.9试一下

@YoKeyword
Copy link
Owner

YoKeyword commented Aug 1, 2017

我这边试了下同时start多个的情况,顺序是没问题,但是onHiddenChanged()回调是有问题,因为Fragment的机制问题,需要这么处理:

start(A);
getSupportFragmentManager().executePendingTransactions();

start(B);
getSupportFragmentManager().executePendingTransactions();

start(C);
getSupportFragmentManager().executePendingTransactions();

start(C);

但是发现在Fragment下start()有点问题,稍后Fix

@YoKeyword
Copy link
Owner

v1.1.0里修复了该问题

需要注意的是鉴于Fragment的机制,在start()多个Fragment时,需要像上面提到的执行fm.executePendingTransactions()

@Gundam0079
Copy link
Author

好的多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants