react-native-tab-view 3.5.1 → 3.5.2
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/README.md +2 -646
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/TabBarItem.js +29 -29
- package/lib/commonjs/TabBarItem.js.map +1 -1
- package/lib/commonjs/TabBarItemLabel.js +36 -0
- package/lib/commonjs/TabBarItemLabel.js.map +1 -0
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/TabBarItem.js +29 -29
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabBarItemLabel.js +28 -0
- package/lib/module/TabBarItemLabel.js.map +1 -0
- package/lib/typescript/src/TabBarIndicator.d.ts +0 -1
- package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItemLabel.d.ts +11 -0
- package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/SceneView.tsx +1 -1
- package/src/TabBarItem.tsx +50 -42
- package/src/TabBarItemLabel.tsx +39 -0
package/src/TabBarItem.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import useLatestCallback from 'use-latest-callback';
|
|
13
13
|
|
|
14
14
|
import { PlatformPressable } from './PlatformPressable';
|
|
15
|
+
import { TabBarItemLabel } from './TabBarItemLabel';
|
|
15
16
|
import type { NavigationState, Route, Scene } from './types';
|
|
16
17
|
|
|
17
18
|
export type Props<T extends Route> = {
|
|
@@ -85,18 +86,26 @@ const getInactiveOpacity = (
|
|
|
85
86
|
|
|
86
87
|
type TabBarItemInternalProps<T extends Route> = Omit<
|
|
87
88
|
Props<T>,
|
|
88
|
-
'navigationState'
|
|
89
|
+
| 'navigationState'
|
|
90
|
+
| 'getAccessibilityLabel'
|
|
91
|
+
| 'getLabelText'
|
|
92
|
+
| 'getTestID'
|
|
93
|
+
| 'getAccessible'
|
|
89
94
|
> & {
|
|
90
95
|
isFocused: boolean;
|
|
91
96
|
index: number;
|
|
92
97
|
routesLength: number;
|
|
98
|
+
accessibilityLabel?: string;
|
|
99
|
+
label?: string;
|
|
100
|
+
testID?: string;
|
|
101
|
+
accessible?: boolean;
|
|
93
102
|
};
|
|
94
103
|
|
|
95
104
|
const TabBarItemInternal = <T extends Route>({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
accessibilityLabel,
|
|
106
|
+
accessible,
|
|
107
|
+
label: labelText,
|
|
108
|
+
testID,
|
|
100
109
|
onLongPress,
|
|
101
110
|
onPress,
|
|
102
111
|
isFocused,
|
|
@@ -166,29 +175,16 @@ const TabBarItemInternal = <T extends Route>({
|
|
|
166
175
|
}
|
|
167
176
|
}
|
|
168
177
|
|
|
169
|
-
const renderLabel =
|
|
170
|
-
renderLabelCustom
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
styles.label,
|
|
180
|
-
icon ? { marginTop: 0 } : null,
|
|
181
|
-
labelStyle,
|
|
182
|
-
{ color: labelProps.color },
|
|
183
|
-
]}
|
|
184
|
-
>
|
|
185
|
-
{labelText}
|
|
186
|
-
</Animated.Text>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return labelText;
|
|
191
|
-
};
|
|
178
|
+
const renderLabel = renderLabelCustom
|
|
179
|
+
? renderLabelCustom
|
|
180
|
+
: (labelProps: { color: string }) => (
|
|
181
|
+
<TabBarItemLabel
|
|
182
|
+
{...labelProps}
|
|
183
|
+
icon={icon}
|
|
184
|
+
label={labelText}
|
|
185
|
+
labelStyle={labelStyle}
|
|
186
|
+
/>
|
|
187
|
+
);
|
|
192
188
|
|
|
193
189
|
if (renderLabel) {
|
|
194
190
|
const activeLabel = renderLabel({
|
|
@@ -225,20 +221,16 @@ const TabBarItemInternal = <T extends Route>({
|
|
|
225
221
|
|
|
226
222
|
const scene = { route };
|
|
227
223
|
|
|
228
|
-
let accessibilityLabel = getAccessibilityLabel(scene);
|
|
229
|
-
|
|
230
224
|
accessibilityLabel =
|
|
231
|
-
typeof accessibilityLabel !== 'undefined'
|
|
232
|
-
? accessibilityLabel
|
|
233
|
-
: getLabelText(scene);
|
|
225
|
+
typeof accessibilityLabel !== 'undefined' ? accessibilityLabel : labelText;
|
|
234
226
|
|
|
235
227
|
const badge = renderBadge ? renderBadge(scene) : null;
|
|
236
228
|
|
|
237
229
|
return (
|
|
238
230
|
<PlatformPressable
|
|
239
231
|
android_ripple={android_ripple}
|
|
240
|
-
testID={
|
|
241
|
-
accessible={
|
|
232
|
+
testID={testID}
|
|
233
|
+
accessible={accessible}
|
|
242
234
|
accessibilityLabel={accessibilityLabel}
|
|
243
235
|
accessibilityRole="tab"
|
|
244
236
|
accessibilityState={{ selected: isFocused }}
|
|
@@ -266,14 +258,31 @@ const MemoizedTabBarItemInternal = React.memo(
|
|
|
266
258
|
) as typeof TabBarItemInternal;
|
|
267
259
|
|
|
268
260
|
export function TabBarItem<T extends Route>(props: Props<T>) {
|
|
269
|
-
const {
|
|
270
|
-
|
|
261
|
+
const {
|
|
262
|
+
onPress,
|
|
263
|
+
onLongPress,
|
|
264
|
+
onLayout,
|
|
265
|
+
navigationState,
|
|
266
|
+
route,
|
|
267
|
+
getAccessibilityLabel,
|
|
268
|
+
getLabelText,
|
|
269
|
+
getTestID,
|
|
270
|
+
getAccessible,
|
|
271
|
+
...rest
|
|
272
|
+
} = props;
|
|
271
273
|
const onPressLatest = useLatestCallback(onPress);
|
|
272
274
|
const onLongPressLatest = useLatestCallback(onLongPress);
|
|
273
275
|
const onLayoutLatest = useLatestCallback(onLayout ? onLayout : () => {});
|
|
274
276
|
|
|
275
277
|
const tabIndex = navigationState.routes.indexOf(route);
|
|
276
278
|
|
|
279
|
+
const scene = { route };
|
|
280
|
+
|
|
281
|
+
const accessibilityLabel = getAccessibilityLabel(scene);
|
|
282
|
+
const label = getLabelText(scene);
|
|
283
|
+
const testID = getTestID(scene);
|
|
284
|
+
const accessible = getAccessible(scene);
|
|
285
|
+
|
|
277
286
|
return (
|
|
278
287
|
<MemoizedTabBarItemInternal
|
|
279
288
|
{...rest}
|
|
@@ -284,16 +293,15 @@ export function TabBarItem<T extends Route>(props: Props<T>) {
|
|
|
284
293
|
route={route}
|
|
285
294
|
index={tabIndex}
|
|
286
295
|
routesLength={navigationState.routes.length}
|
|
296
|
+
accessibilityLabel={accessibilityLabel}
|
|
297
|
+
label={label}
|
|
298
|
+
testID={testID}
|
|
299
|
+
accessible={accessible}
|
|
287
300
|
/>
|
|
288
301
|
);
|
|
289
302
|
}
|
|
290
303
|
|
|
291
304
|
const styles = StyleSheet.create({
|
|
292
|
-
label: {
|
|
293
|
-
margin: 4,
|
|
294
|
-
backgroundColor: 'transparent',
|
|
295
|
-
textTransform: 'uppercase',
|
|
296
|
-
},
|
|
297
305
|
icon: {
|
|
298
306
|
margin: 2,
|
|
299
307
|
},
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
4
|
+
|
|
5
|
+
interface TabBarItemLabelProps {
|
|
6
|
+
color: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
labelStyle: StyleProp<ViewStyle>;
|
|
9
|
+
icon: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TabBarItemLabel = React.memo(
|
|
13
|
+
({ color, label, labelStyle, icon }: TabBarItemLabelProps) => {
|
|
14
|
+
if (!label) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Animated.Text
|
|
20
|
+
style={[
|
|
21
|
+
styles.label,
|
|
22
|
+
icon ? { marginTop: 0 } : null,
|
|
23
|
+
labelStyle,
|
|
24
|
+
{ color: color },
|
|
25
|
+
]}
|
|
26
|
+
>
|
|
27
|
+
{label}
|
|
28
|
+
</Animated.Text>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const styles = StyleSheet.create({
|
|
34
|
+
label: {
|
|
35
|
+
margin: 4,
|
|
36
|
+
backgroundColor: 'transparent',
|
|
37
|
+
textTransform: 'uppercase',
|
|
38
|
+
},
|
|
39
|
+
});
|