@react-navigation/material-top-tabs 8.0.0-alpha.3 → 8.0.0-alpha.30
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/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createMaterialTopTabNavigator.js +3 -7
- package/lib/module/navigators/createMaterialTopTabNavigator.js.map +1 -1
- package/lib/module/utils/useTabAnimation.js +1 -1
- package/lib/module/utils/useTabAnimation.js.map +1 -1
- package/lib/module/views/MaterialTopTabBar.js +72 -20
- package/lib/module/views/MaterialTopTabBar.js.map +1 -1
- package/lib/module/views/MaterialTopTabView.js +48 -4
- package/lib/module/views/MaterialTopTabView.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createMaterialTopTabNavigator.d.ts +8 -14
- package/lib/typescript/src/navigators/createMaterialTopTabNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +61 -36
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/views/MaterialTopTabBar.d.ts.map +1 -1
- package/lib/typescript/src/views/MaterialTopTabView.d.ts.map +1 -1
- package/package.json +17 -18
- package/src/index.tsx +1 -0
- package/src/navigators/createMaterialTopTabNavigator.tsx +10 -46
- package/src/types.tsx +76 -44
- package/src/utils/useTabAnimation.tsx +1 -1
- package/src/views/MaterialTopTabBar.tsx +99 -26
- package/src/views/MaterialTopTabView.tsx +65 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ActivityView } from '@react-navigation/elements/internal';
|
|
1
2
|
import {
|
|
2
3
|
CommonActions,
|
|
3
4
|
type ParamListBase,
|
|
@@ -6,6 +7,8 @@ import {
|
|
|
6
7
|
useLocale,
|
|
7
8
|
useTheme,
|
|
8
9
|
} from '@react-navigation/native';
|
|
10
|
+
import { useMemo, useState } from 'react';
|
|
11
|
+
import { type Animated, StyleSheet } from 'react-native';
|
|
9
12
|
import { TabView } from 'react-native-tab-view';
|
|
10
13
|
|
|
11
14
|
import type {
|
|
@@ -13,6 +16,7 @@ import type {
|
|
|
13
16
|
MaterialTopTabDescriptorMap,
|
|
14
17
|
MaterialTopTabNavigationConfig,
|
|
15
18
|
MaterialTopTabNavigationHelpers,
|
|
19
|
+
MaterialTopTabNavigationOptions,
|
|
16
20
|
} from '../types';
|
|
17
21
|
import { TabAnimationContext } from '../utils/TabAnimationContext';
|
|
18
22
|
import { MaterialTopTabBar } from './MaterialTopTabBar';
|
|
@@ -68,9 +72,14 @@ export function MaterialTopTabView({
|
|
|
68
72
|
});
|
|
69
73
|
}}
|
|
70
74
|
renderScene={({ route, position }) => (
|
|
71
|
-
<
|
|
75
|
+
<SceneContent
|
|
76
|
+
focused={route.key === state.routes[state.index].key}
|
|
77
|
+
preloaded={state.preloadedRouteKeys.includes(route.key)}
|
|
78
|
+
position={position}
|
|
79
|
+
options={descriptors[route.key].options}
|
|
80
|
+
>
|
|
72
81
|
{descriptors[route.key].render()}
|
|
73
|
-
</
|
|
82
|
+
</SceneContent>
|
|
74
83
|
)}
|
|
75
84
|
navigationState={state}
|
|
76
85
|
renderTabBar={renderTabBar}
|
|
@@ -105,3 +114,57 @@ export function MaterialTopTabView({
|
|
|
105
114
|
/>
|
|
106
115
|
);
|
|
107
116
|
}
|
|
117
|
+
|
|
118
|
+
function SceneContent({
|
|
119
|
+
focused,
|
|
120
|
+
preloaded,
|
|
121
|
+
position,
|
|
122
|
+
options,
|
|
123
|
+
children,
|
|
124
|
+
}: {
|
|
125
|
+
focused: boolean;
|
|
126
|
+
preloaded: boolean;
|
|
127
|
+
position: Animated.AnimatedInterpolation<number>;
|
|
128
|
+
options: MaterialTopTabNavigationOptions;
|
|
129
|
+
children: React.ReactNode;
|
|
130
|
+
}) {
|
|
131
|
+
const { inactiveBehavior = 'pause', lazy } = options;
|
|
132
|
+
|
|
133
|
+
const [loaded, setLoaded] = useState(focused);
|
|
134
|
+
|
|
135
|
+
if (focused && !loaded) {
|
|
136
|
+
setLoaded(true);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const animationContext = useMemo(() => ({ position }), [position]);
|
|
140
|
+
|
|
141
|
+
// For preloaded screens and if lazy is false,
|
|
142
|
+
// Keep them active so that the effects can run
|
|
143
|
+
const isActive =
|
|
144
|
+
inactiveBehavior === 'none' ||
|
|
145
|
+
focused ||
|
|
146
|
+
preloaded ||
|
|
147
|
+
(lazy === false && !loaded);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<TabAnimationContext.Provider value={animationContext}>
|
|
151
|
+
<ActivityView
|
|
152
|
+
mode={isActive ? 'normal' : 'paused'}
|
|
153
|
+
visible={
|
|
154
|
+
// Tabs can be swiped quickly
|
|
155
|
+
// So we keep all tabs visible to avoid flash of blank screen
|
|
156
|
+
true
|
|
157
|
+
}
|
|
158
|
+
style={styles.scene}
|
|
159
|
+
>
|
|
160
|
+
{children}
|
|
161
|
+
</ActivityView>
|
|
162
|
+
</TabAnimationContext.Provider>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const styles = StyleSheet.create({
|
|
167
|
+
scene: {
|
|
168
|
+
flex: 1,
|
|
169
|
+
},
|
|
170
|
+
});
|