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

FlowLayout的load、loadParams、loadType属性 #38

Open
Feeeeeerny opened this issue Dec 19, 2017 · 4 comments
Open

FlowLayout的load、loadParams、loadType属性 #38

Feeeeeerny opened this issue Dec 19, 2017 · 4 comments
Labels

Comments

@Feeeeeerny
Copy link

Feeeeeerny commented Dec 19, 2017

请问在TangramFlowLayout布局中的calculateLayout方法中有以下一段代码,是否是可以使用的呢?

    if ((self.loadType == TangramLayoutLoadTypeLoadOnce || self.loadType == TangramLayoutLoadTypeByPage) && self.loadAPI.length > 0) {
        TangramEvent *loadEvent = [[TangramEvent alloc]initWithTopic:@"requestItems" withTangramView:self.tangramView posterIdentifier:@"requestItems" andPoster:self];
        [loadEvent setParam:self.loadAPI forKey:@"loadAPI"];
        [loadEvent setParam:[NSNumber numberWithInteger:self.loadType] forKey:@"loadType"];
        if (self.loadParams.count > 0) {
            [loadEvent setParam:self.loadParams forKey:@"loadParams"];
        }
        [self.tangramBus postEvent:loadEvent];
    }

我在外部注册了该事件的监听,实现了网络请求、回调后刷新数据源,然后[tangramView reloadData],但是在reloadData方法中又会去调用TangramFlowLayout的calculateLayout方法,然后就死循环了。请问怎样可以避免呢?

@HarrisonXi
Copy link
Contributor

这个方法应该被归类为不推荐使用的将废弃方法,这是我们在业务中为了实现首次进入
TangramFlowLayout 时进行一次状态请求的后门,后期维护时可能会从开源版本中移除。

如果您想了解具体的细节的话:

  1. 这里并不是用来刷新页面的(比如我们是触发一次定位请求)
  2. 网络请求应该在代码里去掉重复请求,只执行一次

@Feeeeeerny
Copy link
Author

安卓版本也有这几个字段,我理解他的作用是,异步请求卡片的内容数据。这个功能应该不会去除吧?

@HarrisonXi
Copy link
Contributor

异步加载数据一方面来说比较倾向于业务逻辑,而不是底层框架特性。框架可以在合适的时机抛出 didEnter / didLoaded 等事件供业务层来进行对应功能扩展。

另一方面至少从设计角度来说,不太应该在 calculateLayout 方法中进行数据请求的 Bus 事件发送。

@Feeeeeerny
Copy link
Author

好的,我这里参照安卓,在Tangram的scrollViewDidScroll方法中遍历了visibel layouts,对设置了loadApi的layout发出了asyncload的event,由业务方处理该event。

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