简体   繁体   English

无法关闭模式(react-native-date-picker)

[英]Unable to dimiss a modal (react-native-date-picker)

So we are using this lib react-native-date-picker for date picking (obviously).所以我们正在使用这个 lib react-native-date-picker进行日期选择(显然)。

When user is timeout from app, we are navigating the user back to login screen.当用户从应用程序超时时,我们将用户导航回登录屏幕。 However if the date picker (this is a modal) is opened, it will remain on top of screen as always.但是,如果打开日期选择器(这是一个模式),它将一如既往地保留在屏幕顶部。 Within the library I see no option to decide when the modal should stay visible/invisible.库中,我看不到决定模式何时保持可见/不可见的选项。

Here's few approaches I've tried with no success这是我尝试过的几种方法,但均未成功

  1. Using forwardRef wrapping my child component (which shows the date picker), trying to access the component via Ref.使用forwardRef包装我的子组件(显示日期选择器),尝试通过 Ref 访问组件。 No success, always receive NULL in return.没有成功,总是收到 NULL 作为回报。 I think the library don't support this either?我认为图书馆也不支持这个?

  2. Based on the timeout props we stored in Redux, within the function componentdidupdate we setState to re-render the screen by telling DatePicker's prop open as FALSE.基于我们存储在 Redux 中的超时道具,在函数componentdidupdate中,我们通过将 DatePicker 的道具open为 FALSE 来设置状态以重新渲染屏幕。 No success either.也没有成功。

Im curious on the reason behind why is this happening.我很好奇为什么会发生这种情况。 What are the possible solution?可能的解决方案是什么?

react-native-date-picker uses the corresponding Date picker native module for each platform. react-native-date-picker为每个平台使用相应的日期选择器原生模块。 When the native modal is opened, it runs on the Native thread while your code runs on the JavaScript thread.当原生模式打开时,它在原生线程上运行,而您的代码在 JavaScript 线程上运行。

When the user session expired and the app navigates to Login Screen, React Navigation tries to unmount the current screen component but Date Picker is not mounted because it runs on Native Thread.当用户会话过期并且应用导航到登录屏幕时,React Navigation 会尝试卸载当前屏幕组件,但日期选择器未安装,因为它在本机线程上运行。

Your app logic should detect if the modal is opened before and close it before navigating to Login screen您的应用程序逻辑应检测模式是否在之前打开并在导航到登录屏幕之前将其关闭

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM