如何使用 setTimeout 延迟反应导航操作?
How to delay react-navigation action with setTimeout?
我有一个在嵌套堆栈内导航的导航功能。路线:
- 课程选项卡
-
- 课程项目
函数如下:
const goToCourse = () => {
props.navigation.navigate(
NavigationActions.navigate({
routeName: 'CourseTab',
// Delay this action slightly until slightly after the first navigation has completed.
action: setTimeout(() => {NavigationActions.navigate({
routeName: "CourseItem",
})}, 330)
})
)
}
不幸的是,以这种方式使用 setTimeout 是行不通的。我想知道如何使用替代方法实现此目的?
分离功能。无需使用 action
.
const goToCourse = (courseId) => {
const NaviOne = NavigationActions.navigate({
routeName: 'CourseTab'
})
const NaviTwo = NavigationActions.navigate({
routeName: "CourseItem"
})
props.navigation.dispatch(NaviOne)
setTimeout(() => { props.navigation.dispatch(NaviTwo) }, 1000)
}
我有一个在嵌套堆栈内导航的导航功能。路线:
- 课程选项卡
-
- 课程项目
函数如下:
const goToCourse = () => {
props.navigation.navigate(
NavigationActions.navigate({
routeName: 'CourseTab',
// Delay this action slightly until slightly after the first navigation has completed.
action: setTimeout(() => {NavigationActions.navigate({
routeName: "CourseItem",
})}, 330)
})
)
}
不幸的是,以这种方式使用 setTimeout 是行不通的。我想知道如何使用替代方法实现此目的?
分离功能。无需使用 action
.
const goToCourse = (courseId) => {
const NaviOne = NavigationActions.navigate({
routeName: 'CourseTab'
})
const NaviTwo = NavigationActions.navigate({
routeName: "CourseItem"
})
props.navigation.dispatch(NaviOne)
setTimeout(() => { props.navigation.dispatch(NaviTwo) }, 1000)
}