@tarojs/router-rn 3.5.0-canary.1 → 3.5.0

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.
@@ -1,17 +1,19 @@
1
- /* eslint-disable react/no-children-prop */
2
- import * as React from 'react'
3
- import { StyleProp, ViewStyle } from 'react-native'
4
- import { camelCase } from 'lodash'
1
+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
5
2
  import { NavigationContainer } from '@react-navigation/native'
3
+ import {createNativeStackNavigator, NativeStackNavigationOptions} from '@react-navigation/native-stack'
6
4
  import { BackBehavior } from '@react-navigation/routers/src/TabRouter'
7
- import { createStackNavigator, CardStyleInterpolators } from '@react-navigation/stack'
8
- import { StackHeaderOptions, StackCardMode, StackHeaderMode } from '@react-navigation/stack/src/types'
9
- import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
5
+ import { CardStyleInterpolators, createStackNavigator, StackNavigationOptions } from '@react-navigation/stack'
6
+ import { StackHeaderMode, StackHeaderOptions } from '@react-navigation/stack/src/types'
7
+ import { camelCase } from 'lodash'
8
+ import React from 'react'
9
+ import { StyleProp, ViewStyle } from 'react-native'
10
+
10
11
  import { navigationRef } from './rootNavigation'
11
- import CustomTabBar from './view/TabBar'
12
- import HeadTitle from './view/HeadTitle'
12
+ import { getTabInitRoute, getTabItemConfig, getTabVisible, handleUrl, setTabConfig } from './utils/index'
13
13
  import BackButton from './view/BackButton'
14
- import { getTabItemConfig, getTabVisible, setTabConfig, getTabInitRoute, handleUrl } from './utils/index'
14
+ import HeadTitle from './view/HeadTitle'
15
+ import CustomTabBar from './view/TabBar'
16
+ import { TabOptions } from './view/TabBarItem'
15
17
 
16
18
  interface WindowConfig {
17
19
  pageOrientation?: 'auto' | 'portrait' | 'landscape'
@@ -38,49 +40,49 @@ interface ITabBar {
38
40
  selectedColor?: string
39
41
  backgroundColor?: string
40
42
  borderStyle?: 'black' | 'white'
41
- list: ITabBarItem[],
43
+ list: ITabBarItem[]
42
44
  position?: 'bottom' | 'top'
43
45
  custom?: boolean
44
46
  }
45
47
 
46
48
  interface PageItem {
47
- name: string,
48
- component: any,
49
+ name: string
50
+ component: any
49
51
  pagePath: string
50
52
  }
51
53
 
52
54
  interface RNConfig {
53
- initialRouteName?: string,
54
- linking?: string[],
55
- screenOptions?: Record<string, any>,
56
- tabBarOptions?: Record<string, any>,
57
- options?: Record<string, any>,
58
- tabProps?:{
59
- backBehavior?: BackBehavior;
60
- lazy?: boolean,
61
- detachInactiveScreens?:boolean,
55
+ initialRouteName?: string
56
+ linking?: string[]
57
+ screenOptions?: StackNavigationOptions | NativeStackNavigationOptions
58
+ tabOptions?: TabOptions
59
+ tabBarOptions?: Record<string, any>
60
+ tabProps?: {
61
+ backBehavior?: BackBehavior
62
+ lazy?: boolean
63
+ detachInactiveScreens?:boolean
62
64
  sceneContainerStyle?: StyleProp<ViewStyle>
63
- },
64
- stackProps?:{
65
- keyboardHandlingEnabled?:boolean,
66
- mode?: StackCardMode;
67
- headerMode?: StackHeaderMode;
68
- detachInactiveScreens?:boolean,
69
65
  }
66
+ stackProps?: {
67
+ keyboardHandlingEnabled?:boolean
68
+ headerMode?: StackHeaderMode
69
+ detachInactiveScreens?:boolean
70
+ }
71
+ useNativeStack?: boolean
70
72
  }
71
73
 
72
74
  export interface RouterConfig {
73
- pages: PageItem[],
74
- tabBar?: ITabBar,
75
- window?: WindowConfig,
76
- linkPrefix?: string[],
77
- rnConfig?: RNConfig,
78
- initParams?:Record<string, any>, // 原生启动传递的参数
79
- initPath?: string, // 原生启动时传入的参数路径
80
- entryPagePath?: string, // 默认启动路径
75
+ pages: PageItem[]
76
+ tabBar?: ITabBar
77
+ window?: WindowConfig
78
+ linkPrefix?: string[]
79
+ rnConfig?: RNConfig
80
+ initParams?:Record<string, any> // 原生启动传递的参数
81
+ initPath?: string // 原生启动时传入的参数路径
82
+ entryPagePath?: string // 默认启动路径
81
83
  }
82
84
 
83
- export function createRouter (config: RouterConfig): React.ReactNode {
85
+ export function createRouter (config: RouterConfig) {
84
86
  if (config?.tabBar?.list?.length) {
85
87
  return createTabNavigate(config)
86
88
  } else {
@@ -118,7 +120,7 @@ function getTabItemOptions (item, index: number) {
118
120
  }
119
121
 
120
122
  function getHeaderView (title: string, color: string, props: any) {
121
- return React.createElement(HeadTitle, { label: title, color, headerProps: props }, null)
123
+ return <HeadTitle label={title} color={color} headerProps={props} />
122
124
  }
123
125
 
124
126
  // screen配置的内容
@@ -142,12 +144,12 @@ function getStackOptions (config: RouterConfig) {
142
144
  },
143
145
  headerTintColor: headColor,
144
146
  cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
147
+ cardStyle: { elevation: 1 },
145
148
  headerBackTitleVisible: false,
146
- headerPressColorAndroid: 'rgba(255,255,255,0)',
147
149
  headerTitleAlign,
148
150
  // eslint-disable-next-line react/display-name
149
151
  headerBackImage: ({ tintColor }) => {
150
- return React.createElement(BackButton, { tintColor }, null)
152
+ return <BackButton tintColor={tintColor} />
151
153
  }
152
154
  }
153
155
  const rnConfig = config.rnConfig || {}
@@ -228,29 +230,28 @@ function getInitParams (config, pageName) {
228
230
  return params
229
231
  }
230
232
 
231
- function createTabStack (config: RouterConfig, parentProps: any) {
233
+ function createTabStack (config: RouterConfig, parentProps: any, screenOptions) {
232
234
  const Tab = createBottomTabNavigator()
233
235
  const tabBar = config.tabBar
234
236
  const rnConfig = config.rnConfig
235
237
  const tabList: any = []
236
- const userOptions: Record<string, any> = rnConfig?.options || {}
238
+ const tabOptions: TabOptions = rnConfig?.tabOptions || {}
237
239
  tabBar?.list.forEach((item, index) => {
238
240
  const defaultOptions = Object.assign({}, { tabBarVisible: config.tabBar?.custom ? false : getTabVisible() }, getTabItemOptions(item, index))
239
- const tabItemOptions = Object.assign({}, defaultOptions, userOptions)
241
+ const tabItemOptions = Object.assign({}, defaultOptions, tabOptions, { headerShown: false, title: item.text })
240
242
  setTabConfig('tabBarVisible', tabItemOptions.tabBarVisible)
241
243
  const path = item.pagePath.startsWith('/') ? item.pagePath : `/${item.pagePath}`
242
244
  const tabName = camelCase(path)
243
245
  const tabPage: PageItem = getTabItem(config, tabName) as PageItem
244
246
  const initParams = getInitParams(config, tabName)
245
- const tabNode = React.createElement(Tab.Screen, {
246
- key: `tab${tabName}`,
247
- name: `${tabPage.name}`,
248
- options: tabItemOptions,
249
- component: tabPage.component,
250
- initialParams: initParams,
251
- ...parentProps
252
- })
253
- tabList.push(tabNode)
247
+ tabList.push(<Tab.Screen
248
+ key={`tab${tabName}`}
249
+ name={tabPage.name}
250
+ options={tabItemOptions}
251
+ component={tabPage.component}
252
+ initialParams={initParams}
253
+ {...parentProps}
254
+ />)
254
255
  })
255
256
 
256
257
  const borderColorMap = {
@@ -278,19 +279,16 @@ function createTabStack (config: RouterConfig, parentProps: any) {
278
279
  const tabProps = config.rnConfig?.tabProps || {}
279
280
 
280
281
  const tabInitRouteName = getTabInitRoute() || getInitTabRoute(config) || tabNames[0]
281
- return React.createElement(Tab.Navigator,
282
- {
283
- ...tabProps,
284
- tabBarOptions: tabBarOptions,
285
- tabBar: (props) => createTabBar(props, userOptions),
286
- initialRouteName: tabInitRouteName,
287
- children: tabList
288
- },
289
- tabList)
282
+ return <Tab.Navigator
283
+ {...tabProps}
284
+ tabBar={(props) => createTabBar(props, tabOptions, tabBarOptions)}
285
+ initialRouteName={tabInitRouteName}
286
+ screenOptions={screenOptions}
287
+ >{tabList}</Tab.Navigator>
290
288
  }
291
289
 
292
- function createTabBar (props, userOptions) {
293
- return React.createElement(CustomTabBar, { ...props, userOptions })
290
+ function createTabBar (props, tabOptions: TabOptions, tabBarOptions) {
291
+ return <CustomTabBar {...props} tabOptions={tabOptions} {...tabBarOptions} />
294
292
  }
295
293
 
296
294
  function getLinkingConfig (config: RouterConfig) {
@@ -330,74 +328,61 @@ function getLinkingConfig (config: RouterConfig) {
330
328
  }
331
329
 
332
330
  function createTabNavigate (config: RouterConfig) {
333
- const screeList: any = []
334
- const Stack = createStackNavigator()
335
- // 第一个页面是tabbar的
336
- const tabScreen = React.createElement(Stack.Screen, {
337
- name: 'tabNav',
338
- key: 'tabScreen',
339
- children: (props) => createTabStack(config, props)
340
- }, (props) => createTabStack(config, props))
341
- screeList.push(tabScreen)
331
+ const Stack = config.rnConfig?.useNativeStack ? createNativeStackNavigator() : createStackNavigator()
342
332
  const pageList = getPageList(config)
343
- pageList.forEach(item => {
344
- const initParams = getInitParams(config, item.name)
345
- const screenNode = React.createElement(Stack.Screen,
346
- {
347
- key: `${item.name}`,
348
- name: `${item.name}`,
349
- component: item.component,
350
- initialParams: initParams
351
- }, null)
352
- screeList.push(screenNode)
353
- })
354
333
  const linking = getLinkingConfig(config)
355
334
  const stackProps = config.rnConfig?.stackProps
356
- const tabStack = React.createElement(Stack.Navigator,
357
- {
358
- ...stackProps,
359
- screenOptions: () => {
360
- const options = getCurrentOptions()
361
- const defaultOptions = getStackOptions(config)
362
- return Object.assign({}, defaultOptions, options)
363
- },
364
- initialRouteName: getInitRouteName(config),
365
- children: screeList
366
- }, screeList)
367
- return React.createElement(NavigationContainer, { ref: navigationRef, linking: linking, children: tabStack }, tabStack)
335
+ const screenOptions = getStackOptions(config)
336
+ return <NavigationContainer
337
+ ref={navigationRef}
338
+ linking={linking}
339
+ >
340
+ <Stack.Navigator
341
+ detachInactiveScreens={false}
342
+ {...stackProps}
343
+ // @ts-ignore
344
+ screenOptions={screenOptions}
345
+ initialRouteName={getInitRouteName(config)}
346
+ >
347
+ <Stack.Screen
348
+ name='tabNav'
349
+ key='tabScreen'
350
+ options={{
351
+ headerShown: false
352
+ }}
353
+ >{(props) => createTabStack(config, props, screenOptions)}</Stack.Screen>
354
+ {pageList.map(item => {
355
+ const initParams = getInitParams(config, item.name)
356
+ return <Stack.Screen
357
+ key={item.name}
358
+ name={item.name}
359
+ component={item.component}
360
+ initialParams={initParams}
361
+ ></Stack.Screen>
362
+ })}
363
+ </Stack.Navigator>
364
+ </NavigationContainer>
368
365
  }
369
366
 
370
367
  function createStackNavigate (config: RouterConfig) {
371
- const Stack = createStackNavigator()
368
+ const Stack = config.rnConfig?.useNativeStack ? createNativeStackNavigator() : createStackNavigator()
372
369
  const pageList = getPageList(config)
373
370
  if (pageList.length <= 0) return null
374
- const screenChild: any = []
375
- pageList.forEach(item => {
376
- const initParams = getInitParams(config, item.name)
377
- const screenNode = React.createElement(Stack.Screen,
378
- {
379
- key: `${item.name}`,
380
- name: `${item.name}`,
381
- component: item.component,
382
- initialParams: initParams
383
- }, null)
384
- screenChild.push(screenNode)
385
- })
386
371
  const linking = getLinkingConfig(config)
387
372
  const stackProps = config.rnConfig?.stackProps
388
- const stackNav = React.createElement(Stack.Navigator,
389
- {
390
- ...stackProps,
391
- screenOptions: getStackOptions(config),
392
- children: screenChild,
393
- initialRouteName: getInitRouteName(config)
394
- }, screenChild)
395
- return React.createElement(NavigationContainer, { ref: navigationRef, linking: linking, children: stackNav }, stackNav)
396
- }
397
-
398
- function getCurrentOptions () {
399
- const options = navigationRef.current?.getCurrentOptions() || {}
400
- const params: Record<string, any> = navigationRef.current?.getCurrentRoute()?.params || {}
401
- const navParams = params?.navigateConfig || {}
402
- return Object.assign({}, options, navParams)
373
+ return <NavigationContainer
374
+ ref={navigationRef}
375
+ linking={linking}
376
+ >
377
+ <Stack.Navigator
378
+ detachInactiveScreens={false}
379
+ {...stackProps}
380
+ // @ts-ignore
381
+ screenOptions={getStackOptions(config)}
382
+ initialRouteName={getInitRouteName(config)}
383
+ >{pageList.map(item => {
384
+ const initParams = getInitParams(config, item.name)
385
+ return <Stack.Screen key={item.name} name={item.name} component={item.component} initialParams={initParams} />
386
+ })}</Stack.Navigator>
387
+ </NavigationContainer>
403
388
  }
package/src/tabBar.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { successHandler, errorHandler, setTabConfig } from './utils/index'
2
- import { CallbackResult, TaroTabBarConfig, BaseOption } from './utils/types'
3
1
  import { navigationRef } from './rootNavigation'
2
+ import { errorHandler, setTabConfig, successHandler } from './utils/index'
3
+ import { BaseOption, CallbackResult, TaroTabBarConfig } from './utils/types'
4
4
 
5
5
  const globalAny: any = global
6
6
  const INIT_TABBAR_ICON_CONFIG: TaroTabBarConfig = {
@@ -11,19 +11,19 @@ const INIT_TABBAR_ICON_CONFIG: TaroTabBarConfig = {
11
11
  }
12
12
  globalAny.__taroTabBarIconConfig = INIT_TABBAR_ICON_CONFIG
13
13
  interface TabBarBadge extends BaseOption {
14
- index: number,
14
+ index: number
15
15
  text?: number | string
16
16
  }
17
17
 
18
18
  interface TabBarRedDot extends BaseOption {
19
- index: number,
19
+ index: number
20
20
  }
21
21
 
22
22
  interface TabBarItem extends BaseOption {
23
- index: number,
24
- text?: string,
25
- iconPath?: string,
26
- selectedIconPath?: string,
23
+ index: number
24
+ text?: string
25
+ iconPath?: string
26
+ selectedIconPath?: string
27
27
  }
28
28
 
29
29
  interface TabBarOptions extends BaseOption {
@@ -31,9 +31,9 @@ interface TabBarOptions extends BaseOption {
31
31
  }
32
32
 
33
33
  interface TabBarStyleOption extends BaseOption {
34
- backgroundColor?: string,
35
- borderStyle?: 'white' | 'black',
36
- color?: string,
34
+ backgroundColor?: string
35
+ borderStyle?: 'white' | 'black'
36
+ color?: string
37
37
  selectedColor?: string
38
38
  }
39
39
 
@@ -1,6 +1,7 @@
1
1
  import { camelCase } from 'lodash'
2
2
  import { parseUrl } from 'query-string'
3
- import { TaroTabBarConfig, CallbackResult, OptionsFunc } from './types'
3
+
4
+ import { CallbackResult, OptionsFunc, TaroTabBarConfig } from './types'
4
5
 
5
6
  const globalAny: any = global
6
7
 
@@ -35,7 +36,6 @@ export function isFunction (obj: unknown): boolean {
35
36
  return typeof obj === 'function'
36
37
  }
37
38
 
38
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
39
39
  export function isEmptyObject (obj: any): boolean {
40
40
  if (obj == null) {
41
41
  return true
@@ -1,22 +1,22 @@
1
1
  export interface TabItemConfig {
2
- showRedDot?: boolean,
3
- tabBarBadge?: string | number,
4
- tabBarLabel?: string,
5
- iconPath?: string,
6
- selectedIconPath?: string,
2
+ showRedDot?: boolean
3
+ tabBarBadge?: string | number
4
+ tabBarLabel?: string
5
+ iconPath?: string
6
+ selectedIconPath?: string
7
7
  }
8
8
 
9
9
  // 设置全局的tabbar config 中的内容定义
10
10
  export interface TaroTabBarConfig {
11
- needAnimate: boolean,
12
- tabBarVisible: boolean,
11
+ needAnimate: boolean
12
+ tabBarVisible: boolean
13
13
  tabStyle: {
14
- backgroundColor?: string,
15
- borderStyle?: string,
16
- color?: string,
14
+ backgroundColor?: string
15
+ borderStyle?: string
16
+ color?: string
17
17
  selectedColor?: string
18
- },
19
- tabItems: Record<number, TabItemConfig>,
18
+ }
19
+ tabItems: Record<number, TabItemConfig>
20
20
  }
21
21
 
22
22
  export interface CallbackResult {
@@ -1,6 +1,5 @@
1
- // eslint-disable-next-line no-use-before-define
2
1
  import * as React from 'react'
3
- import { View, Image, Platform } from 'react-native'
2
+ import { Image, Platform, View } from 'react-native'
4
3
 
5
4
  interface BackButtonProps {
6
5
  tintColor: string
@@ -10,7 +9,6 @@ export const blackArrow = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAD
10
9
  export const whiteArrow = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAJQElEQVR4Xu2dv4veRRCHZ/4DOxsLsbyACAkIdjbmL4hdQGwk2Ihg7V2tYCfBRhBUSGNjZ6MIsQqinVUKLdLZxMbmK2+4w0ty7/vuj5nd2d3nmhTZmZ19PvPw5nKQqPAFAQjsJaCwgQAE9hNAELYDAgcIIAjrAQEEYQcgUEaAT5AyblQtQgBBFgmaZ5YRQJAyblQtQgBBFgmaZ5YRQJAyblQtQgBBFgmaZ5YRQJAyblQtQgBBFgmaZ5YRQJAyblQtQgBBFgm65pnbtr0lItdFZPfrTyLym6p+V9NzlFoEGSWpDnNu2/aCiHwsIh9ccf3PIvK2qj7qMFqzKxGkGeqxLtq27UREvhaR145M/o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EHasTa9CUlMce5thiBtOLvcgiQuWJ9qiiD+jF1vQBJXvIIgvnybdEcSP8wI4se2aWck8cGNID5cu3RFEnvsCGLPtGtHJLHFjyC2PEN0QxK7GBDEjmWoTkhiEweC2HAM2QVJ6mNBkHqGoTsgSV08CFLHb4hqJCmPCUHK2Q1ViSRlcSFIGbchq5AkPzYEyWc2dAWS5MWHIHm8pjhtKMmZqp5OAWXPIxBk5nQPvM1QkjuqendWjAgya7IJ7zKS5LGI3FTV+wlXDncEQYaLzHZgI0m+UNX3bCeL0Q1BYuTQdQoDSR6o6o2uj3C6HEGcwI7WtlYSVZ1yl6Z81GjLGWXeCkl+VNU3o7zDcg4EsaQ5Qa9CST5V1Y8meP5zT0CQGVOtfFOmJI9E5ERV/668NmQ5goSMpf9Q55J8KyKvHpnmhqo+6D+xzwQI4sN1iq7btr0oIp+IyO0rHvSDiLyrqn9N8dg9j0CQmdM1etu2bbdE5HURuS4iv4vIryLyjar+a3RF2DYIEjYaBotAAEEipMAMYQkgSNhoGCwCAQSJkAIzhCWAIGGjYbAIBBAkQgrMEJYAgoSNhsEiEECQCCkwQ1gCCBI2GgaLQABBIqTADGEJIEjYaBgsAgEEiZACM4QlgCBho2GwCAQQJEIKzBCWwH9HJ2P28zYs1wAAAABJRU5ErkJggg=='
11
10
 
12
11
  export default class BackButton extends React.PureComponent<BackButtonProps> {
13
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
14
12
  render () {
15
13
  const { tintColor = '#ffffff' } = this.props
16
14
  const color = tintColor.toLowerCase()
@@ -1,16 +1,15 @@
1
- // eslint-disable-next-line no-use-before-define
2
1
  import * as React from 'react'
3
- import { Animated, StyleSheet, StyleProp, TextStyle } from 'react-native'
2
+ import { Animated, StyleProp, StyleSheet, TextStyle } from 'react-native'
4
3
 
5
4
  export interface BadgeProps {
6
- visible: boolean,
7
- children?: string | number,
8
- size?: number,
5
+ visible: boolean
6
+ children?: string | number
7
+ size?: number
9
8
  style?: Animated.WithAnimatedValue<StyleProp<TextStyle>>
10
9
  }
11
10
 
12
11
  export interface BadgeState {
13
- opacity: Animated.Value,
12
+ opacity: Animated.Value
14
13
  visible: boolean
15
14
  }
16
15
 
@@ -62,7 +61,6 @@ export default class Badge extends React.PureComponent<BadgeProps, BadgeState> {
62
61
  }
63
62
  }
64
63
 
65
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
66
64
  render () {
67
65
  const { opacity } = this.state
68
66
  const { style, size = 18, children, visible } = this.props
@@ -72,7 +70,6 @@ export default class Badge extends React.PureComponent<BadgeProps, BadgeState> {
72
70
  const borderRadius = size / 2
73
71
  const fontSize = Math.floor((size * 3) / 4)
74
72
 
75
- // eslint-disable-next-line multiline-ternary
76
73
  return (!visible ? null
77
74
  : (
78
75
  <Animated.Text
@@ -1,17 +1,16 @@
1
- // eslint-disable-next-line no-use-before-define
2
1
  import * as React from 'react'
3
- import { View, Text } from 'react-native'
4
- import Loading from './Loading'
2
+ import { Text, View } from 'react-native'
3
+
5
4
  import { navigationRef } from '../rootNavigation'
5
+ import Loading from './Loading'
6
6
 
7
7
  export interface HeadTitleProps {
8
- label: string,
9
- color: string,
8
+ label: string
9
+ color: string
10
10
  headerProps?: any
11
11
  }
12
12
 
13
13
  export default class HeadTitle extends React.PureComponent<HeadTitleProps> {
14
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
15
14
  render () {
16
15
  // showLoading自定义的参数放在params中
17
16
  const params: Record<string, any> = navigationRef.current?.getCurrentRoute()?.params || {}
@@ -1,9 +1,8 @@
1
- // eslint-disable-next-line no-use-before-define
2
1
  import * as React from 'react'
3
- import { Animated, StyleSheet, Easing } from 'react-native'
2
+ import { Animated, Easing, StyleSheet } from 'react-native'
4
3
 
5
4
  interface LoadingViewState {
6
- rotateValue: Animated.Value,
5
+ rotateValue: Animated.Value
7
6
  }
8
7
 
9
8
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -38,7 +37,6 @@ class LoadingView extends React.Component<LoadingViewProps, LoadingViewState> {
38
37
  }).start(() => this.startAnimation())
39
38
  }
40
39
 
41
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
42
40
  render () {
43
41
  return (
44
42
  <Animated.Image
@@ -1,44 +1,45 @@
1
- // eslint-disable-next-line no-use-before-define
2
- import * as React from 'react'
3
1
  import {
4
2
  Link
5
3
  } from '@react-navigation/native'
6
- import { withSafeAreaInsets } from 'react-native-safe-area-context'
4
+ import * as React from 'react'
7
5
  import {
8
- View,
9
- TouchableWithoutFeedback,
10
6
  Animated,
11
- StyleSheet,
12
- Platform,
13
7
  Dimensions,
8
+ EmitterSubscription,
9
+ Keyboard,
14
10
  LayoutChangeEvent,
15
- Keyboard
11
+ Platform,
12
+ StyleSheet,
13
+ TouchableWithoutFeedback,
14
+ View
16
15
  } from 'react-native'
17
- import { getTabVisible, getTabConfig, getTabItemConfig, getDefalutTabItem, isUrl } from '../utils/index'
18
- import { getInitSafeAreaInsets } from './tabBarUtils'
16
+ import { withSafeAreaInsets } from 'react-native-safe-area-context'
17
+
18
+ import { getDefalutTabItem, getTabConfig, getTabItemConfig, getTabVisible, isUrl } from '../utils/index'
19
19
  import TabBarItem, { TabBarOptions, TabOptions } from './TabBarItem'
20
+ import { getInitSafeAreaInsets } from './tabBarUtils'
20
21
 
21
22
  interface TabBarProps extends TabBarOptions {
22
- state: Record<string, any>,
23
- navigation: any,
24
- descriptors: Record<string, any>,
25
- userOptions: TabOptions
23
+ state: Record<string, any>
24
+ navigation: any
25
+ descriptors: Record<string, any>
26
+ tabOptions: TabOptions
26
27
  }
27
28
 
28
29
  interface TabBarState {
29
- visible: Animated.Value,
30
- isKeyboardShown: boolean,
31
- tabVisible: boolean,
30
+ visible: Animated.Value
31
+ isKeyboardShown: boolean
32
+ tabVisible: boolean
32
33
  layout: {
33
- height: number,
34
- width: number,
35
- },
34
+ height: number
35
+ width: number
36
+ }
36
37
  insets: Record<string, number>
37
38
  }
38
39
  interface TabBarStyle {
39
- color?: string,
40
- selectedColor?: string,
41
- backgroundColor?: string,
40
+ color?: string
41
+ selectedColor?: string
42
+ backgroundColor?: string
42
43
  borderStyle?: string
43
44
  }
44
45
 
@@ -71,11 +72,13 @@ const styles = StyleSheet.create({
71
72
  })
72
73
 
73
74
  export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
75
+ handleKeyboardShowEvent: EmitterSubscription
76
+ handleKeyboardHideEvent: EmitterSubscription
74
77
  constructor (props: TabBarProps) {
75
78
  super(props)
76
79
  const { height = 0, width = 0 } = Dimensions.get('window')
77
- const { safeAreaInsets, userOptions = {} } = this.props
78
- const { tabBarVisible = true } = userOptions
80
+ const { safeAreaInsets, tabOptions = {} } = this.props
81
+ const { tabBarVisible = true } = tabOptions
79
82
  const tabVisible = tabBarVisible === false ? false : getTabVisible()
80
83
  this.state = {
81
84
  visible: new Animated.Value(tabVisible ? 1 : 0),
@@ -93,11 +96,11 @@ export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
93
96
  const { keyboardHidesTabBar = false } = this.props
94
97
  if (keyboardHidesTabBar) {
95
98
  if (Platform.OS === 'ios') {
96
- Keyboard.addListener('keyboardWillShow', () => this.handleKeyboardShow())
97
- Keyboard.addListener('keyboardWillHide', () => this.handleKeyboardHide())
99
+ this.handleKeyboardShowEvent = Keyboard.addListener('keyboardWillShow', () => this.handleKeyboardShow())
100
+ this.handleKeyboardHideEvent = Keyboard.addListener('keyboardWillHide', () => this.handleKeyboardHide())
98
101
  } else {
99
- Keyboard.addListener('keyboardDidShow', () => this.handleKeyboardShow())
100
- Keyboard.addListener('keyboardDidHide', () => this.handleKeyboardHide())
102
+ this.handleKeyboardShowEvent = Keyboard.addListener('keyboardDidShow', () => this.handleKeyboardShow())
103
+ this.handleKeyboardHideEvent = Keyboard.addListener('keyboardDidHide', () => this.handleKeyboardHide())
101
104
  }
102
105
  }
103
106
  }
@@ -105,13 +108,8 @@ export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
105
108
  componentWillUnmount () {
106
109
  const { keyboardHidesTabBar = false } = this.props
107
110
  if (keyboardHidesTabBar) {
108
- if (Platform.OS === 'ios') {
109
- Keyboard.removeListener('keyboardWillShow', () => this.handleKeyboardShow())
110
- Keyboard.removeListener('keyboardWillHide', () => this.handleKeyboardHide())
111
- } else {
112
- Keyboard.removeListener('keyboardDidShow', () => this.handleKeyboardShow())
113
- Keyboard.removeListener('keyboardDidHide', () => this.handleKeyboardHide())
114
- }
111
+ this.handleKeyboardShowEvent.remove()
112
+ this.handleKeyboardHideEvent.remove()
115
113
  }
116
114
  }
117
115
 
@@ -229,7 +227,6 @@ export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
229
227
  return isUrl(path) ? { uri: path } : { uri: path }
230
228
  }
231
229
 
232
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
233
230
  renderContent () {
234
231
  const { state, descriptors, navigation } = this.props
235
232
  const horizontal = true
@@ -336,7 +333,6 @@ export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
336
333
  </View>
337
334
  }
338
335
 
339
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
340
336
  render () {
341
337
  const { insets, visible, layout, tabVisible, isKeyboardShown } = this.state
342
338
  const paddingBottom = Math.max(
@@ -349,7 +345,6 @@ export class TabBar extends React.PureComponent<TabBarProps, TabBarState> {
349
345
 
350
346
  const showTabBar = tabVisible !== false && !isKeyboardShown
351
347
  if (!needAnimate) {
352
- // eslint-disable-next-line multiline-ternary
353
348
  return (!showTabBar ? null
354
349
  : (
355
350
  <View