Skip to content

Commit

Permalink
fix(rn): [RN]Taro.getCurrentPages方法不存在 close NervJS#3224
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng authored and cncolder committed Mar 3, 2020
1 parent 17549d6 commit c4fd51c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
25 changes: 17 additions & 8 deletions packages/taro-router-rn/src/TaroProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@ class TaroProvider extends React.Component {
this.refreshProviderRef = React.createRef()
}

componentDidMount () {
navigationMethodInit () {
let {Taro} = this.props
Taro.navigateTo = this.wxNavigateTo.bind(this)
Taro.redirectTo = this.wxRedirectTo.bind(this)
Taro.navigateBack = this.wxNavigateBack.bind(this)
Taro.switchTab = this.wxSwitchTab.bind(this)
Taro.getCurrentPages = this.wxGetCurrentPages.bind(this)
Taro.showTabBar = this.showTabBar.bind(this)
Taro.hideTabBar = this.hideTabBar.bind(this)
}

componentWillMount () {
this.navigationMethodInit()
// didFocus
this.didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
// 页面进入后回退并不会调用 React 生命周期,需要在路由生命周期中绑定 this
Taro.navigateTo = this.wxNavigateTo.bind(this)
Taro.redirectTo = this.wxRedirectTo.bind(this)
Taro.navigateBack = this.wxNavigateBack.bind(this)
Taro.switchTab = this.wxSwitchTab.bind(this)
Taro.getCurrentPages = this.wxGetCurrentPages.bind(this)
Taro.showTabBar = this.showTabBar.bind(this)
Taro.hideTabBar = this.hideTabBar.bind(this)
this.navigationMethodInit()
}
)
}

componentDidMount () {
let {Taro} = this.props
try {
Taro.startPullDownRefresh = this.refreshProviderRef.current && this.refreshProviderRef.current.handlePullDownRefresh
Taro.stopPullDownRefresh = this.refreshProviderRef.current && this.refreshProviderRef.current.stopPullDownRefresh
Expand Down
15 changes: 10 additions & 5 deletions packages/taro-router-rn/src/getWrappedScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,21 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) {
}
}

componentDidMount () {
navigationMethodInit () {
Taro.setNavigationBarTitle = this.setNavigationBarTitle.bind(this)
Taro.setNavigationBarColor = this.setNavigationBarColor.bind(this)
Taro.showNavigationBarLoading = this.showNavigationBarLoading.bind(this)
Taro.hideNavigationBarLoading = this.hideNavigationBarLoading.bind(this)
}

componentWillMount () {
this.navigationMethodInit()
// didFocus
this.didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
// 页面进入后回退并不会调用 React 生命周期,需要在路由生命周期中绑定 this
Taro.setNavigationBarTitle = this.setNavigationBarTitle.bind(this)
Taro.setNavigationBarColor = this.setNavigationBarColor.bind(this)
Taro.showNavigationBarLoading = this.showNavigationBarLoading.bind(this)
Taro.hideNavigationBarLoading = this.hideNavigationBarLoading.bind(this)
this.navigationMethodInit()
// 页面聚焦时,调用 componentDidShow
this.getScreenInstance().componentDidShow && this.getScreenInstance().componentDidShow()
}
Expand Down

0 comments on commit c4fd51c

Please sign in to comment.