Skip to content

Commit

Permalink
fix(rn): 修复rn端onTabItemTap参数为空的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yechunxi committed Mar 8, 2023
1 parent f0e1520 commit d8c9b8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/taro-runtime-rn/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { eventCenter } from './emmiter'
import EventChannel from './EventChannel'
import { Instance, PageInstance } from './instance'
import { BackgroundOption, BaseOption, CallbackResult, HooksMethods, PageConfig, ScrollOption, TextStyleOption } from './types/index'
import { EMPTY_OBJ, errorHandler, incrementId, isArray, isFunction, successHandler } from './utils'
import { EMPTY_OBJ, errorHandler, getPageStr, incrementId, isArray, isFunction, successHandler } from './utils'

const compId = incrementId()

Expand Down Expand Up @@ -40,7 +40,6 @@ function getLifecyle (instance, lifecyle) {

function safeExecute (path: string, lifecycle: keyof Instance, ...args: unknown[]) {
const instance = instances.get(path)

if (instance == null) {
return
}
Expand Down Expand Up @@ -280,7 +279,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
}

pullDownRefresh = (path, refresh) => {
if (path === pagePath) {
if (getPageStr(path) === getPageStr(pagePath)) {
this.setState({ refreshing: refresh })
}
}
Expand All @@ -294,7 +293,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
}

pageToScroll = ({ path = '', scrollTop = 0 }) => {
if (path === pagePath) {
if (getPageStr(path) === getPageStr(pagePath)) {
this.pageScrollView?.current?.scrollTo({ x: 0, y: scrollTop, animated: true })
}
}
Expand Down Expand Up @@ -387,8 +386,8 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
let result: Record<string, unknown> = {}
for (let i = 0; i < tabBar.list.length; i++) {
const item = tabBar.list[i]
const path = item.pagePath.startsWith('/') ? item.pagePath : `/${item.pagePath}`
if (path === itemPath) {
const path = item.pagePath.replace(/^\//, '') || ''
if (getPageStr(path) === getPageStr(itemPath)) {
result = {
index: i,
pagePath: path,
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-runtime-rn/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ export function errorHandler (fail: OptionsFunc | undefined, complete: OptionsFu
return Promise.reject(res)
}
}

export function getPageStr (path: string):string{
return path.replace(/\//g,'')
}

0 comments on commit d8c9b8a

Please sign in to comment.