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

Fix blank screen(#37) #39

Closed
wants to merge 1 commit into from
Closed

Fix blank screen(#37) #39

wants to merge 1 commit into from

Conversation

Jeepeng
Copy link

@Jeepeng Jeepeng commented Mar 14, 2018

注释掉了debounce部分代码:

if (payload.type === 'Navigation/NAVIGATE') {
    yield call(delay, 500);
}

原因是段代码会导致每当路由跳转时,500ms内所有的navigation action都不会被执行,这不是理想的解决快速双击跳转两次的方案。

@nihgwu
Copy link
Owner

nihgwu commented Mar 15, 2018

其实如果注释掉了那部分debounce的代码,那么router watcher甚至整个router model都完全没有存在的必要了,因为我创建它就是为了劫持navigation actions然后给特定的action加debounce
而且从issue里的讨论来看,debounce应该是相对来说比较合理的做法,因为极快速的navigate是没有意义的
其实你直接加上新的actions,debounce那段不去掉就可以了
不过我在想目前这种做法确实不太好,如果后来react-navigation又新加了actions,这边又要同步,我觉得可以直接遍历NavigationActions里面的string然后如果是以Navigation/开头就push到actions里,但是感觉新的action NavigationActions.PUSH也应该debounce掉

@Jeepeng
Copy link
Author

Jeepeng commented Mar 15, 2018

不去掉的话,还是会出现空白屏的情况:
Home -> Account -> Goto Login -> Close -> Home

11

NavigationActions.PUSH之后,delay 500ms,挡住期间所有的Navigation/* action
例如解决这个问题时:Best pattern for a 'Save' button in the header

static navigationOptions = ({ navigation: { state } }) => {
  return {
    title: 'title',
    headerRight: (
      <Button
        ...
        onPress={() => state.params.onPressRight()}>
        <Text>提交</Text>
      </Button>
    ),
  };
};
...
componentDidMount() {
  ...
  this.props.navigation.setParams({
    onPressRight: this.submit,
  });
}

debounce的做法会 block setParams,导致其setParams不生效:

@nihgwu
Copy link
Owner

nihgwu commented Mar 15, 2018

哦,我测试的时候还有其他修改,去掉之后果然还是白屏,如果是因为delay造成的,我觉得是我那段所谓的debounce的代码逻辑写的有问题,应该使用真正的 leading debounce

@neeboo
Copy link

neeboo commented Mar 15, 2018

其实debounce的考虑是不是为了避免快速多次点击导致stack重复出现的问题?

那为啥不在点击上面做处理呢?

@nihgwu
Copy link
Owner

nihgwu commented Mar 15, 2018

点击就会有相应的action以及reducer,我现在就是在reducer里面处理,只是看起来处理的不对
如果是处理点击那每个地方都要加相应的逻辑了

@neeboo
Copy link

neeboo commented Mar 15, 2018

delay 500ms确实会白屏,为了能尽快进入开发,我把它设置成了100ms,setParams确实没法用,还需要再想办法

@nihgwu
Copy link
Owner

nihgwu commented Mar 15, 2018

嗯,我有时间也再看看这部分逻辑

@bestlbw
Copy link

bestlbw commented Mar 17, 2018

快速点击可以不可以这样做,判断2次action是否相同,如果相同只执行一次,这样会不会好一点 @nihgwu

@nihgwu
Copy link
Owner

nihgwu commented Mar 26, 2018

thanks for contributing, close in flavor of 83f9623

@nihgwu nihgwu closed this Mar 26, 2018
@trexguo
Copy link

trexguo commented May 5, 2018

@nihgwu 你好

用redux-logger打印出来watcher里的action只有

router/handlePush/@@start
router/watch/@@start

没有@@end

如果在这里自己再加监听然后put别的model里的action,也会没有@@end

希望能调查一下

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.

5 participants