@tarojs/runtime-rn 3.7.0-alpha.2 → 3.7.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/app.tsx CHANGED
@@ -1,21 +1,28 @@
1
1
  import { Provider as TCNProvider } from '@tarojs/components-rn'
2
- import { createRouter, RouterConfig } from '@tarojs/router-rn'
3
- import React, { Component, ComponentClass,ComponentProps, createRef } from 'react'
2
+ import React, { Component, ComponentProps, createElement, createRef, forwardRef } from 'react'
4
3
  import { RootSiblingParent } from 'react-native-root-siblings'
5
4
 
6
5
  import { Current } from './current'
7
- import { AppInstance } from './instance'
6
+ import EventChannel from './EventChannel'
7
+ import { AppInstance, PageLifeCycle } from './instance'
8
+ import { getPageInstance } from './page'
9
+ import { createRouter, getInitOptions, getRouteEventChannel } from './router'
8
10
  import { RNAppConfig } from './types/index'
9
- import { isFunction } from './utils'
11
+ import { HOOKS_APP_ID, isFunction } from './utils'
10
12
 
11
13
  export function isClassComponent (component): boolean {
12
- return isFunction(component.render) ||
13
- !!component.prototype?.isReactComponent ||
14
- component.prototype instanceof Component
14
+ return (
15
+ isFunction(component?.render) || !!component.prototype?.isReactComponent || component.prototype instanceof Component
16
+ )
15
17
  }
16
18
 
17
- export function createReactNativeApp (component: ComponentClass, config: RNAppConfig) {
18
- const routerConfig: RouterConfig = {
19
+ export function createReactNativeApp (AppEntry: any, config: RNAppConfig, FirstPage: any) {
20
+ const singleMode = config?.appConfig?.rn?.singleMode ?? false
21
+ const needNavigate = config.pageList.length !== 1 || !singleMode
22
+ if (needNavigate) {
23
+ getRouteEventChannel(EventChannel.routeChannel)
24
+ }
25
+ const routerConfig: any = {
19
26
  tabBar: config.appConfig.tabBar,
20
27
  pages: config.pageList,
21
28
  entryPagePath: config.appConfig.entryPagePath,
@@ -24,77 +31,132 @@ export function createReactNativeApp (component: ComponentClass, config: RNAppCo
24
31
  rnConfig: config.appConfig.rn || {}
25
32
  }
26
33
 
27
- const ref = createRef<AppInstance>()
34
+ const appRef = createRef<AppInstance>()
35
+ const isReactComponent = isClassComponent(AppEntry)
36
+ let entryComponent: any = AppEntry
37
+ if (!isReactComponent) {
38
+ // eslint-disable-next-line react/display-name
39
+ entryComponent = forwardRef((props, ref) => {
40
+ return <AppEntry forwardRef={ref} {...props} />
41
+ })
42
+ }
28
43
 
29
- const isReactComponent = isClassComponent(component)
44
+ const NewAppComponent = (AppComponent) => {
45
+ return class Entry extends Component<any, any> {
46
+ constructor (props) {
47
+ super(props)
48
+ const { initPath = '', initParams = {} } = this.props
49
+ routerConfig.initPath = initPath
50
+ routerConfig.initParams = initParams
51
+ }
52
+
53
+ componentDidMount () {
54
+ let options: any = {}
55
+ if (needNavigate) {
56
+ options = getInitOptions(routerConfig)
57
+ }
58
+ triggerAppLifecycle('onLaunch', options)
59
+ triggerAppLifecycle('componentDidShow', options)
60
+ }
61
+
62
+ // 导航onUnhandledAction
63
+ onUnhandledAction (options) {
64
+ triggerAppLifecycle('onPageNotFound', options)
65
+ }
30
66
 
31
- const NewAppComponent = (AppCompoent) => {
32
- return class Entry extends Component <any, any> {
33
67
  render () {
34
- let props: ComponentProps<any> | null = null
68
+ const props: ComponentProps<any> | null = null
35
69
 
36
- if (isReactComponent) {
37
- props = { ref }
38
- }
39
- const { initPath = '', initParams = {} } = this.props
40
70
  const appProps = {
41
71
  ...props,
42
72
  ...this.props
43
73
  }
44
- routerConfig.initPath = initPath
45
- routerConfig.initParams = initParams
46
- return <RootSiblingParent>
47
- <TCNProvider {...this.props}>
48
- <AppCompoent {...appProps}>
49
- {createRouter(routerConfig)}
50
- </AppCompoent>
51
- </TCNProvider>
52
- </RootSiblingParent>
74
+
75
+ let routerOptions: any = {}
76
+ if (needNavigate) {
77
+ routerOptions = {
78
+ onUnhandledAction: this.onUnhandledAction
79
+ }
80
+ }
81
+
82
+ const child = needNavigate
83
+ ? createRouter(routerConfig, routerOptions)
84
+ : createElement(FirstPage, { ...this.props }, [])
85
+
86
+ return createElement(
87
+ RootSiblingParent,
88
+ null,
89
+ createElement(
90
+ TCNProvider,
91
+ { ...this.props },
92
+ createElement(AppComponent, { ...appProps, ref: appRef }, child)
93
+ )
94
+ )
53
95
  }
54
96
  }
55
97
  }
56
98
 
57
- const App = NewAppComponent(component)
99
+ const App = NewAppComponent(entryComponent)
58
100
 
59
101
  // 与小程序端实例保持一致
60
- const appInst = Object.create({}, {
61
- config: {
62
- writable: true,
63
- enumerable: true,
64
- configurable: true,
65
- value: config.appConfig
66
- },
67
- onLaunch: {
68
- enumerable: true,
69
- writable: true,
70
- value (options) {
71
- const app = ref.current
72
- if (app != null && isFunction(app.onLaunch)) {
73
- app.onLaunch && app.onLaunch(options)
102
+ const appInst = Object.create(
103
+ {},
104
+ {
105
+ config: {
106
+ writable: true,
107
+ enumerable: true,
108
+ configurable: true,
109
+ value: config.appConfig
110
+ },
111
+ onLaunch: {
112
+ enumerable: true,
113
+ writable: true,
114
+ value (options) {
115
+ triggerAppLifecycle('onLaunch', options)
74
116
  }
75
- }
76
- },
77
- onShow: {
78
- enumerable: true,
79
- writable: true,
80
- value (options) {
81
- const app = ref.current
82
- if (app != null && isFunction(app.componentDidShow)) {
83
- app.componentDidShow && app.componentDidShow(options)
117
+ },
118
+ onShow: {
119
+ enumerable: true,
120
+ writable: true,
121
+ value (options) {
122
+ triggerAppLifecycle('componentDidShow', options)
123
+ }
124
+ },
125
+ onHide: {
126
+ enumerable: true,
127
+ writable: true,
128
+ value (options: unknown) {
129
+ triggerAppLifecycle('componentDidHide', options)
130
+ }
131
+ },
132
+ onPageNotFound: {
133
+ enumerable: true,
134
+ writable: true,
135
+ value (options) {
136
+ triggerAppLifecycle('onPageNotFound', options)
84
137
  }
85
138
  }
86
- },
87
- onHide: {
88
- enumerable: true,
89
- writable: true,
90
- value (options: unknown) {
91
- const app = ref.current
92
- if (app != null && isFunction(app.componentDidHide)) {
93
- app.componentDidHide && app.componentDidHide(options)
139
+ }
140
+ )
141
+
142
+ function triggerAppLifecycle (lifecycle: keyof PageLifeCycle | keyof AppInstance, ...args) {
143
+ try {
144
+ const app = appRef.current
145
+ if (isReactComponent) {
146
+ app?.[lifecycle] && app?.[lifecycle](...args)
147
+ } else {
148
+ const instance = getPageInstance(HOOKS_APP_ID)
149
+ if (instance) {
150
+ const func = instance[lifecycle]
151
+ if (Array.isArray(func)) {
152
+ func.forEach((cb) => cb.apply(app, args))
153
+ }
94
154
  }
95
155
  }
156
+ } catch (err) {
157
+ throw new Error(err)
96
158
  }
97
- })
159
+ }
98
160
 
99
161
  Current.app = appInst
100
162
  return App
package/src/current.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { navigationRef as rnNavigationRef } from '@tarojs/router-rn'
2
1
  import * as React from 'react'
3
2
 
4
3
  import { AppInstance, PageInstance } from './instance'
4
+ import { rnNavigationRef } from './router'
5
5
 
6
6
  interface Router {
7
7
  params: Record<string, unknown>
package/src/hooks.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react'
2
2
 
3
3
  import { Current } from './current'
4
- import { PageLifeCycle } from './instance'
4
+ import { AppInstance, PageLifeCycle } from './instance'
5
5
  import { getPageInstance, injectPageInstance, PageContext } from './page'
6
- import { isArray, isFunction } from './utils'
6
+ import { HOOKS_APP_ID, isArray, isFunction } from './utils'
7
7
 
8
- const taroHooks = (lifecycle: keyof PageLifeCycle) => {
8
+ const taroHooks = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
9
9
  // eslint-disable-next-line @typescript-eslint/ban-types
10
10
  return (fn: Function) => {
11
- const id = React.useContext(PageContext)
11
+ const id = React.useContext(PageContext) || HOOKS_APP_ID
12
12
 
13
13
  const fnRef = React.useRef(fn)
14
14
  if (fnRef.current !== fn) fnRef.current = fn
@@ -70,6 +70,10 @@ export const useResize = taroHooks('onResize')
70
70
 
71
71
  export const useTabItemTap = taroHooks('onTabItemTap')
72
72
 
73
+ export const useLaunch = taroHooks('onLaunch')
74
+
75
+ export const usePageNotFound= taroHooks('onPageNotFound')
76
+
73
77
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
74
78
  export const useRouter = (dynamic = false) => {
75
79
  return dynamic ? Current.router : React.useMemo(() => Current.router, [])
package/src/index.ts CHANGED
@@ -20,10 +20,6 @@ export {
20
20
  startPullDownRefresh,
21
21
  stopPullDownRefresh
22
22
  } from './page'
23
- export {
24
- scalePx2dp,
25
- scaleVu2dp
26
- } from './scale2dp'
27
23
  export {
28
24
  hideNavigationBarLoading,
29
25
  hideTabBar,
@@ -42,4 +38,8 @@ export {
42
38
  showTabBar,
43
39
  showTabBarRedDot,
44
40
  switchTab
45
- } from '@tarojs/router-rn'
41
+ } from './router'
42
+ export {
43
+ scalePx2dp,
44
+ scaleVu2dp
45
+ } from './scale2dp'
package/src/instance.ts CHANGED
@@ -35,4 +35,5 @@ export interface PageInstance extends PageLifeCycle {
35
35
 
36
36
  export interface AppInstance extends Show {
37
37
  onLaunch?(options?: string): void
38
+ onPageNotFound?(options?: string): void
38
39
  }
package/src/page.ts CHANGED
@@ -1,13 +1,21 @@
1
- import { getCurrentRoute, isTabPage, PageProvider } from '@tarojs/router-rn'
2
1
  import { Component, Context, createContext, createElement, createRef, forwardRef, RefObject } from 'react'
3
- import { AppState, Dimensions, EmitterSubscription, NativeEventSubscription, RefreshControl, ScrollView } from 'react-native'
2
+ import { AppState, Dimensions, EmitterSubscription, RefreshControl, ScrollView } from 'react-native'
4
3
 
5
4
  import { isClassComponent } from './app'
6
5
  import { Current } from './current'
7
6
  import { eventCenter } from './emmiter'
8
7
  import EventChannel from './EventChannel'
9
8
  import { Instance, PageInstance } from './instance'
10
- import { BackgroundOption, BaseOption, CallbackResult, HooksMethods, PageConfig, ScrollOption, TextStyleOption } from './types/index'
9
+ import { getCurrentRoute, isTabPage, PageProvider } from './router'
10
+ import {
11
+ BackgroundOption,
12
+ BaseOption,
13
+ CallbackResult,
14
+ HooksMethods,
15
+ PageConfig,
16
+ ScrollOption,
17
+ TextStyleOption
18
+ } from './types/index'
11
19
  import { EMPTY_OBJ, errorHandler, getPageStr, incrementId, isArray, isFunction, successHandler } from './utils'
12
20
 
13
21
  const compId = incrementId()
@@ -46,7 +54,7 @@ function safeExecute (path: string, lifecycle: keyof Instance, ...args: unknown[
46
54
  const func = getLifecyle(instance, lifecycle)
47
55
 
48
56
  if (isArray(func)) {
49
- const res = func.map(fn => fn.apply(instance, args))
57
+ const res = func.map((fn) => fn.apply(instance, args))
50
58
  return res[0]
51
59
  }
52
60
  if (!isFunction(func)) {
@@ -64,9 +72,14 @@ export let PageContext: Context<string> = EMPTY_OBJ
64
72
  let appState = AppState.currentState
65
73
 
66
74
  AppState.addEventListener('change', (nextAppState) => {
67
- const { page } = Current
75
+ const { page, app, router } = Current
68
76
  if (!page) return
69
77
  if (appState.match(/inactive|background/) && nextAppState === 'active') {
78
+ app?.onShow &&
79
+ app.onShow({
80
+ path: router?.path,
81
+ query: router?.params
82
+ })
70
83
  if (!page.__isReactComponent && page.__safeExecute) {
71
84
  page.__safeExecute('componentDidShow')
72
85
  } else if (page.onShow) {
@@ -79,6 +92,7 @@ AppState.addEventListener('change', (nextAppState) => {
79
92
  } else if (page.onHide) {
80
93
  page.onHide()
81
94
  }
95
+ app?.onHide && app.onHide()
82
96
  }
83
97
  appState = nextAppState
84
98
  })
@@ -121,20 +135,20 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
121
135
  unSubscribleFocus: any
122
136
  unSubscribleTabPress: any
123
137
  pageId: string
124
- appStateSubscription: NativeEventSubscription | undefined
125
138
  dimensionsSubscription: EmitterSubscription | undefined
126
139
  isPageReady: boolean
127
140
 
128
141
  constructor (props: any) {
129
142
  super(props)
130
143
  const refreshStyle = globalAny?.__taroRefreshStyle ?? {}
131
- const backgroundTextStyle = pageConfig.backgroundTextStyle || globalAny.__taroAppConfig?.appConfig?.window?.backgroundTextStyle || 'dark'
144
+ const backgroundTextStyle =
145
+ pageConfig.backgroundTextStyle || globalAny.__taroAppConfig?.appConfig?.window?.backgroundTextStyle || 'dark'
132
146
  this.state = {
133
147
  refreshing: false, // 刷新指示器
134
- appState: AppState.currentState,
135
148
  textColor: refreshStyle.textColor || (backgroundTextStyle === 'dark' ? '#000000' : '#ffffff'),
136
149
  backgroundColor: refreshStyle.backgroundColor || '#ffffff'
137
150
  }
151
+ appState = AppState.currentState
138
152
  this.screenRef = createRef<Instance>()
139
153
  this.pageScrollView = createRef()
140
154
  this.setPageInstance()
@@ -150,16 +164,15 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
150
164
  this.unSubscribleTabPress = navigation.addListener('tabPress', () => this.onTabItemTap())
151
165
  this.unSubscribleFocus = navigation.addListener('focus', () => this.onFocusChange())
152
166
  this.unSubscribleBlur = navigation.addListener('blur', () => this.onBlurChange())
167
+ // 如果是tabbar页面,因为tabbar是懒加载的,第一次点击事件还未监听,不会触发,初始化触发一下
168
+ const lazy = globalAny.__taroAppConfig?.appConfig?.rn?.tabOptions?.lazy ?? true
169
+ if (isTabPage() && lazy) {
170
+ this.onTabItemTap()
171
+ }
153
172
  }
154
173
  eventCenter.on('__taroPullDownRefresh', this.pullDownRefresh, this)
155
174
  eventCenter.on('__taroPageScrollTo', this.pageToScroll, this)
156
175
  eventCenter.on('__taroSetRefreshStyle', this.setRefreshStyle, this)
157
-
158
- // 如果是tabbar页面,因为tabbar是懒加载的,第一次点击事件还未监听,不会触发,初始化触发一下
159
- const lazy = globalAny.__taroAppConfig?.appConfig?.rn?.tabOptions?.lazy ?? true
160
- if(isTabPage() && lazy){
161
- this.onTabItemTap()
162
- }
163
176
  }
164
177
 
165
178
  componentWillUnmount () {
@@ -182,7 +195,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
182
195
  setPageInstance () {
183
196
  const pageRef = this.screenRef
184
197
  const pageId = this.pageId
185
- const { params = {}, key = '' } = this.props.route
198
+ const { params = {}, key = '' } = this.props.route ?? {}
186
199
  // 和小程序的page实例保持一致
187
200
  const inst: PageInstance = {
188
201
  config: pageConfig,
@@ -304,7 +317,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
304
317
  try {
305
318
  this.handleHooksEvent('componentDidShow')
306
319
  // 实现 useReady hook,遵循小程序事件机制,在useDidShow之后触发
307
- if(!this.isPageReady){
320
+ if (!this.isPageReady) {
308
321
  this.handleHooksEvent('onReady')
309
322
  this.isPageReady = true
310
323
  }
@@ -317,20 +330,24 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
317
330
  onBlurChange () {
318
331
  try {
319
332
  this.handleHooksEvent('componentDidHide')
320
- if (this.screenRef?.current?.componentDidHide) { this.screenRef?.current?.componentDidHide() }
333
+ if (this.screenRef?.current?.componentDidHide) {
334
+ this.screenRef?.current?.componentDidHide()
335
+ }
321
336
  } catch (err) {
322
337
  throw new Error(err)
323
338
  }
324
339
  }
325
340
 
326
341
  onPageScroll (e) {
327
- if(!e?.nativeEvent) return
342
+ if (!e?.nativeEvent) return
328
343
  const { contentOffset } = e.nativeEvent
329
344
  const scrollTop = contentOffset.y
330
345
  if (scrollTop < 0) return
331
346
  try {
332
347
  this.handleHooksEvent('onPageScroll', { scrollTop })
333
- if (this.screenRef?.current?.onPageScroll) { this.screenRef?.current?.onPageScroll({ scrollTop }) }
348
+ if (this.screenRef?.current?.onPageScroll) {
349
+ this.screenRef?.current?.onPageScroll({ scrollTop })
350
+ }
334
351
  } catch (err) {
335
352
  throw new Error(err)
336
353
  }
@@ -338,13 +355,15 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
338
355
 
339
356
  // 监听的onMomentumScrollEnd
340
357
  onReachBottom (e) {
341
- if(!e?.nativeEvent) return
358
+ if (!e?.nativeEvent) return
342
359
  const { onReachBottomDistance = 50 } = pageConfig
343
360
  const { layoutMeasurement, contentSize, contentOffset } = e.nativeEvent
344
361
  if (contentOffset?.y + layoutMeasurement?.height + onReachBottomDistance >= contentSize.height) {
345
362
  try {
346
363
  this.handleHooksEvent('onReachBottom')
347
- if (this.screenRef?.current?.onReachBottom) { this.screenRef?.current?.onReachBottom() }
364
+ if (this.screenRef?.current?.onReachBottom) {
365
+ this.screenRef?.current?.onReachBottom()
366
+ }
348
367
  } catch (err) {
349
368
  throw new Error(err)
350
369
  }
@@ -356,7 +375,9 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
356
375
  this.setState({ refreshing: true })
357
376
  try {
358
377
  this.handleHooksEvent('onPullDownRefresh')
359
- if (this.screenRef?.current?.onPullDownRefresh) { this.screenRef?.current?.onPullDownRefresh() }
378
+ if (this.screenRef?.current?.onPullDownRefresh) {
379
+ this.screenRef?.current?.onPullDownRefresh()
380
+ }
360
381
  } catch (e) {
361
382
  throw new Error(e)
362
383
  } finally {
@@ -368,16 +389,16 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
368
389
  try {
369
390
  const item = this.getTabItem(pagePath)
370
391
  this.handleHooksEvent('onTabItemTap', { ...item })
371
- if (this.screenRef?.current?.onTabItemTap) { this.screenRef?.current?.onTabItemTap(item) }
392
+ if (this.screenRef?.current?.onTabItemTap) {
393
+ this.screenRef?.current?.onTabItemTap(item)
394
+ }
372
395
  } catch (error) {
373
396
  throw new Error(error)
374
397
  }
375
398
  }
376
399
 
377
400
  handleHooksEvent (method: HooksMethods, options: Record<string, unknown> = {}) {
378
- if (!isReactComponent) {
379
- return safeExecute(this.pageId, method, options)
380
- }
401
+ return safeExecute(this.pageId, method, options)
381
402
  }
382
403
 
383
404
  getTabItem (itemPath: string) {
@@ -406,46 +427,58 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
406
427
 
407
428
  refreshPullDown () {
408
429
  const { refreshing, textColor, backgroundColor } = this.state
409
- return createElement(RefreshControl, {
410
- refreshing: refreshing,
411
- enabled: true,
412
- titleColor: textColor,
413
- tintColor: textColor,
414
- colors: [backgroundColor],
415
- onRefresh: () => this.onPullDownRefresh()
416
- }, null)
430
+ return createElement(
431
+ RefreshControl,
432
+ {
433
+ refreshing: refreshing,
434
+ enabled: true,
435
+ titleColor: textColor,
436
+ tintColor: textColor,
437
+ colors: [backgroundColor],
438
+ onRefresh: () => this.onPullDownRefresh()
439
+ },
440
+ null
441
+ )
417
442
  }
418
443
 
419
444
  createPage () {
420
- return h(PageProvider, { currentPath: pagePath, pageConfig, ...this.props },
421
- h(PageContext.Provider, { value: this.pageId }, h(Screen,
422
- { ...this.props, ref: this.screenRef })
445
+ if (PageProvider) {
446
+ return h(
447
+ PageProvider,
448
+ { currentPath: pagePath, pageConfig, ...this.props },
449
+ h(PageContext.Provider, { value: this.pageId }, h(Screen, { ...this.props, ref: this.screenRef }))
423
450
  )
424
- )
451
+ }
452
+ return h(PageContext.Provider, { value: this.pageId }, h(Screen, { ...this.props, ref: this.screenRef }))
425
453
  }
426
454
 
427
455
  createScrollPage () {
428
456
  let bgColor = pageConfig.backgroundColor ? pageConfig.backgroundColor : ''
429
457
  const windowOptions = globalAny.__taroAppConfig?.appConfig?.window || {}
430
- const useNativeStack = globalAny.__taroAppConfig?.appConfig?.rn?.useNativeStack
458
+ const useNativeStack = globalAny.__taroAppConfig?.appConfig?.rn?.useNativeStack
431
459
  if (!bgColor && windowOptions?.backgroundColor) {
432
460
  bgColor = windowOptions?.backgroundColor
433
461
  }
434
462
  const refresh = this.isEnablePullDown() ? { refreshControl: this.refreshPullDown() } : {}
435
- return h(ScrollView, {
436
- style: [{ flex: 1 }, (bgColor ? { backgroundColor: bgColor } : {})],
437
- contentContainerStyle: useNativeStack ? {} : { minHeight: '100%' },
438
- ref: this.pageScrollView,
439
- scrollEventThrottle: 8,
440
- ...refresh,
441
- onScroll: (e) => this.onPageScroll(e),
442
- onMomentumScrollEnd: (e) => this.onReachBottom(e)
443
- }, this.createPage())
463
+ return h(
464
+ ScrollView,
465
+ {
466
+ style: [{ flex: 1 }, bgColor ? { backgroundColor: bgColor } : {}],
467
+ contentContainerStyle: useNativeStack ? {} : { minHeight: '100%' },
468
+ ref: this.pageScrollView,
469
+ scrollEventThrottle: 8,
470
+ ...refresh,
471
+ onScroll: (e) => this.onPageScroll(e),
472
+ onMomentumScrollEnd: (e) => this.onReachBottom(e),
473
+ nestedScrollEnabled: true
474
+ },
475
+ this.createPage()
476
+ )
444
477
  }
445
478
 
446
479
  render () {
447
480
  const { disableScroll = false } = pageConfig
448
- return (!disableScroll ? this.createScrollPage() : this.createPage())
481
+ return !disableScroll ? this.createScrollPage() : this.createPage()
449
482
  }
450
483
  }
451
484
  }
@@ -546,11 +579,12 @@ export function getCurrentPages () {
546
579
  const pages: PageInstance[] = []
547
580
  const routes = getCurrentRoute()
548
581
  if (routes && routes.length > 0) {
549
- routes.forEach(item => {
582
+ routes.forEach((item) => {
550
583
  const inst = getPageObject(item)
551
584
  inst && pages.push(inst)
552
585
  })
553
- } else { // 第一次初始化时,getCurrentRoute会为空
586
+ } else {
587
+ // 第一次初始化时,getCurrentRoute会为空
554
588
  const inst = Current.page
555
589
  inst && pages.push(inst)
556
590
  }
package/src/router.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * router-rn 接口都改为require 引入, 单页不引用的router
3
+ *
4
+ */
5
+ let routerObj: any = {}
6
+ try {
7
+ routerObj = require('@tarojs/router-rn')
8
+ // eslint-disable-next-line
9
+ } catch (e) {}
10
+
11
+ function getApi (key){
12
+ if (!routerObj?.[key]) {
13
+ return () => {
14
+ console.error(`Single page can not support ${key}, if you have multiple pages configured, you can try restart and reset cache`)
15
+ }
16
+ }
17
+ return routerObj?.[key]
18
+ }
19
+
20
+ export const rnNavigationRef = routerObj?.navigationRef ?? null
21
+ export const PageProvider = routerObj?.PageProvider ?? null
22
+
23
+ export const getRouteEventChannel = getApi('getRouteEventChannel')
24
+ export const getCurrentRoute = getApi('getCurrentRoute')
25
+ export const isTabPage = getApi('isTabPage')
26
+
27
+ export const createRouter = getApi('createRouter')
28
+ export const getInitOptions = getApi('getInitOptions')
29
+
30
+ export const hideNavigationBarLoading = getApi('hideNavigationBarLoading')
31
+ export const hideTabBar = getApi('hideTabBar')
32
+ export const hideTabBarRedDot = getApi('hideTabBarRedDot')
33
+ export const navigateBack = getApi('navigateBack')
34
+ export const navigateTo = getApi('navigateTo')
35
+ export const redirectTo = getApi('redirectTo')
36
+ export const reLaunch = getApi('reLaunch')
37
+ export const switchTab = getApi('switchTab')
38
+ export const removeTabBarBadge = getApi('removeTabBarBadge')
39
+ export const setNavigationBarColor = getApi('setNavigationBarColor')
40
+ export const setNavigationBarTitle = getApi('setNavigationBarTitle')
41
+ export const setTabBarBadge = getApi('setTabBarBadge')
42
+ export const setTabBarItem = getApi('setTabBarItem')
43
+ export const setTabBarStyle = getApi('setTabBarStyle')
44
+ export const showNavigationBarLoading = getApi('showNavigationBarLoading')
45
+ export const showTabBar = getApi('showTabBar')
46
+ export const showTabBarRedDot = getApi('showTabBarRedDot')
47
+
48
+
49
+
50
+
51
+
@@ -159,7 +159,7 @@ export interface AppConfig {
159
159
  tabBar?: TabBar
160
160
  subPackages?: SubPackage[]
161
161
  subpackages?: SubPackage[]
162
- designWidth: number | ((size: number) => number)
162
+ designWidth: number | ((size?: string | number) => number)
163
163
  deviceRatio: Record<string, number>
164
164
  linkPrefix: string[]
165
165
  rn?: any
package/src/utils.ts CHANGED
@@ -41,6 +41,8 @@ export function isFunction (o: unknown): o is (...args: any[]) => any {
41
41
 
42
42
  export const EMPTY_OBJ: any = {}
43
43
 
44
+ export const HOOKS_APP_ID = 'taro-app'
45
+
44
46
  export const isArray = Array.isArray
45
47
 
46
48
  export function successHandler (success: OptionsFunc | undefined, complete: OptionsFunc | undefined): any {
@@ -60,5 +62,5 @@ export function errorHandler (fail: OptionsFunc | undefined, complete: OptionsFu
60
62
  }
61
63
 
62
64
  export function getPageStr (path: string):string{
63
- return path.replace(/\//g,'')
65
+ return path.replace(/\//g, '')
64
66
  }