@react-navigation/elements 2.0.0-alpha.5 → 2.0.0-alpha.7
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/commonjs/Header/Header.js +10 -12
- package/lib/commonjs/Header/Header.js.map +1 -1
- package/lib/commonjs/Header/HeaderBackButton.js +4 -23
- package/lib/commonjs/Header/HeaderBackButton.js.map +1 -1
- package/lib/commonjs/Header/HeaderButton.js +60 -0
- package/lib/commonjs/Header/HeaderButton.js.map +1 -0
- package/lib/commonjs/Header/getDefaultHeaderHeight.js +5 -1
- package/lib/commonjs/Header/getDefaultHeaderHeight.js.map +1 -1
- package/lib/commonjs/Header/getHeaderTitle.js.map +1 -1
- package/lib/commonjs/Label/getLabel.js.map +1 -1
- package/lib/commonjs/PlatformPressable.js.map +1 -1
- package/lib/commonjs/Screen.js +4 -0
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Header/Header.js +10 -12
- package/lib/module/Header/Header.js.map +1 -1
- package/lib/module/Header/HeaderBackButton.js +4 -23
- package/lib/module/Header/HeaderBackButton.js.map +1 -1
- package/lib/module/Header/HeaderButton.js +52 -0
- package/lib/module/Header/HeaderButton.js.map +1 -0
- package/lib/module/Header/getDefaultHeaderHeight.js +6 -2
- package/lib/module/Header/getDefaultHeaderHeight.js.map +1 -1
- package/lib/module/Header/getHeaderTitle.js.map +1 -1
- package/lib/module/Label/getLabel.js.map +1 -1
- package/lib/module/PlatformPressable.js.map +1 -1
- package/lib/module/Screen.js +4 -0
- package/lib/module/Screen.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Header/Header.d.ts.map +1 -1
- package/lib/typescript/src/Header/HeaderBackButton.d.ts.map +1 -1
- package/lib/typescript/src/Header/HeaderButton.d.ts +4 -0
- package/lib/typescript/src/Header/HeaderButton.d.ts.map +1 -0
- package/lib/typescript/src/Header/getDefaultHeaderHeight.d.ts +1 -1
- package/lib/typescript/src/Header/getDefaultHeaderHeight.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +26 -26
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/Header/Header.tsx +63 -69
- package/src/Header/HeaderBackButton.tsx +5 -20
- package/src/Header/HeaderButton.tsx +54 -0
- package/src/Header/getDefaultHeaderHeight.tsx +8 -2
- package/src/Header/getHeaderTitle.tsx +2 -2
- package/src/Label/getLabel.tsx +2 -2
- package/src/PlatformPressable.tsx +2 -2
- package/src/Screen.tsx +3 -0
- package/src/index.tsx +1 -0
- package/src/types.tsx +27 -27
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { PlatformPressable } from '../PlatformPressable';
|
|
5
|
+
import type { HeaderButtonProps } from '../types';
|
|
6
|
+
|
|
7
|
+
export function HeaderButton({
|
|
8
|
+
disabled,
|
|
9
|
+
onPress,
|
|
10
|
+
pressColor,
|
|
11
|
+
pressOpacity,
|
|
12
|
+
accessibilityLabel,
|
|
13
|
+
testID,
|
|
14
|
+
style,
|
|
15
|
+
href,
|
|
16
|
+
children,
|
|
17
|
+
}: HeaderButtonProps) {
|
|
18
|
+
return (
|
|
19
|
+
<PlatformPressable
|
|
20
|
+
disabled={disabled}
|
|
21
|
+
href={href}
|
|
22
|
+
accessibilityLabel={accessibilityLabel}
|
|
23
|
+
testID={testID}
|
|
24
|
+
onPress={onPress}
|
|
25
|
+
pressColor={pressColor}
|
|
26
|
+
pressOpacity={pressOpacity}
|
|
27
|
+
android_ripple={androidRipple}
|
|
28
|
+
style={[styles.container, disabled && styles.disabled, style]}
|
|
29
|
+
hitSlop={Platform.select({
|
|
30
|
+
ios: undefined,
|
|
31
|
+
default: { top: 16, right: 16, bottom: 16, left: 16 },
|
|
32
|
+
})}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
</PlatformPressable>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const androidRipple = {
|
|
40
|
+
borderless: true,
|
|
41
|
+
foreground: Platform.OS === 'android' && Platform.Version >= 23,
|
|
42
|
+
radius: 20,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const styles = StyleSheet.create({
|
|
46
|
+
container: {
|
|
47
|
+
flexDirection: 'row',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
paddingHorizontal: 8,
|
|
50
|
+
},
|
|
51
|
+
disabled: {
|
|
52
|
+
opacity: 0.5,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
1
|
+
import { PixelRatio, Platform } from 'react-native';
|
|
2
2
|
|
|
3
3
|
import type { Layout } from '../types';
|
|
4
4
|
|
|
5
5
|
export function getDefaultHeaderHeight(
|
|
6
6
|
layout: Layout,
|
|
7
7
|
modalPresentation: boolean,
|
|
8
|
-
|
|
8
|
+
topInset: number
|
|
9
9
|
): number {
|
|
10
10
|
let headerHeight;
|
|
11
11
|
|
|
12
|
+
// On models with Dynamic Island the status bar height is smaller than the safe area top inset.
|
|
13
|
+
const hasDynamicIsland = Platform.OS === 'ios' && topInset > 50;
|
|
14
|
+
const statusBarHeight = hasDynamicIsland
|
|
15
|
+
? topInset - (5 + 1 / PixelRatio.get())
|
|
16
|
+
: topInset;
|
|
17
|
+
|
|
12
18
|
const isLandscape = layout.width > layout.height;
|
|
13
19
|
|
|
14
20
|
if (Platform.OS === 'ios') {
|
package/src/Label/getLabel.tsx
CHANGED
|
@@ -101,8 +101,8 @@ export function PlatformPressable({
|
|
|
101
101
|
pressColor !== undefined
|
|
102
102
|
? pressColor
|
|
103
103
|
: dark
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
? 'rgba(255, 255, 255, .32)'
|
|
105
|
+
: 'rgba(0, 0, 0, .32)',
|
|
106
106
|
...android_ripple,
|
|
107
107
|
}
|
|
108
108
|
: undefined
|
package/src/Screen.tsx
CHANGED
|
@@ -65,6 +65,9 @@ export function Screen(props: Props) {
|
|
|
65
65
|
accessibilityElementsHidden={!focused}
|
|
66
66
|
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
|
|
67
67
|
style={[styles.container, style]}
|
|
68
|
+
// On Fabric we need to disable collapsing for the background to ensure
|
|
69
|
+
// that we won't render unnecessary views due to the view flattening.
|
|
70
|
+
collapsable={false}
|
|
68
71
|
>
|
|
69
72
|
<View style={styles.content}>
|
|
70
73
|
<HeaderShownContext.Provider
|
package/src/index.tsx
CHANGED
|
@@ -7,6 +7,7 @@ export { Header } from './Header/Header';
|
|
|
7
7
|
export { HeaderBackButton } from './Header/HeaderBackButton';
|
|
8
8
|
export { HeaderBackContext } from './Header/HeaderBackContext';
|
|
9
9
|
export { HeaderBackground } from './Header/HeaderBackground';
|
|
10
|
+
export { HeaderButton } from './Header/HeaderButton';
|
|
10
11
|
export { HeaderHeightContext } from './Header/HeaderHeightContext';
|
|
11
12
|
export { HeaderShownContext } from './Header/HeaderShownContext';
|
|
12
13
|
export { HeaderTitle } from './Header/HeaderTitle';
|
package/src/types.tsx
CHANGED
|
@@ -148,6 +148,26 @@ export type HeaderTitleProps = {
|
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
export type HeaderButtonProps = {
|
|
151
|
+
/**
|
|
152
|
+
* Callback to call when the button is pressed.
|
|
153
|
+
*/
|
|
154
|
+
onPress?: () => void;
|
|
155
|
+
/**
|
|
156
|
+
* The `href` to use for the anchor tag on web
|
|
157
|
+
*/
|
|
158
|
+
href?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Whether the button is disabled.
|
|
161
|
+
*/
|
|
162
|
+
disabled?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Accessibility label for the button for screen readers.
|
|
165
|
+
*/
|
|
166
|
+
accessibilityLabel?: string;
|
|
167
|
+
/**
|
|
168
|
+
* ID to locate this button in tests.
|
|
169
|
+
*/
|
|
170
|
+
testID?: string;
|
|
151
171
|
/**
|
|
152
172
|
* Tint color for the header button.
|
|
153
173
|
*/
|
|
@@ -161,28 +181,20 @@ export type HeaderButtonProps = {
|
|
|
161
181
|
*/
|
|
162
182
|
pressOpacity?: number;
|
|
163
183
|
/**
|
|
164
|
-
*
|
|
165
|
-
*/
|
|
166
|
-
canGoBack?: boolean;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export type HeaderBackButtonProps = HeaderButtonProps & {
|
|
170
|
-
/**
|
|
171
|
-
* Whether the button is disabled.
|
|
184
|
+
* Style object for the button.
|
|
172
185
|
*/
|
|
173
|
-
|
|
186
|
+
style?: StyleProp<ViewStyle>;
|
|
174
187
|
/**
|
|
175
|
-
*
|
|
188
|
+
* Content to render for the button. Usually the icon.
|
|
176
189
|
*/
|
|
177
|
-
|
|
190
|
+
children: React.ReactNode;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export type HeaderBackButtonProps = Omit<HeaderButtonProps, 'children'> & {
|
|
178
194
|
/**
|
|
179
195
|
* Function which returns a React Element to display custom image in header's back button.
|
|
180
196
|
*/
|
|
181
197
|
backImage?: (props: { tintColor: string }) => React.ReactNode;
|
|
182
|
-
/**
|
|
183
|
-
* The `href` to use for the anchor tag on web
|
|
184
|
-
*/
|
|
185
|
-
href?: string;
|
|
186
198
|
/**
|
|
187
199
|
* Label text for the button. Usually the title of the previous screen.
|
|
188
200
|
* By default, this is only shown on iOS.
|
|
@@ -217,16 +229,4 @@ export type HeaderBackButtonProps = HeaderButtonProps & {
|
|
|
217
229
|
* Layout of the title element in the header.
|
|
218
230
|
*/
|
|
219
231
|
titleLayout?: Layout;
|
|
220
|
-
/**
|
|
221
|
-
* Accessibility label for the button for screen readers.
|
|
222
|
-
*/
|
|
223
|
-
accessibilityLabel?: string;
|
|
224
|
-
/**
|
|
225
|
-
* ID to locate this button in tests.
|
|
226
|
-
*/
|
|
227
|
-
testID?: string;
|
|
228
|
-
/**
|
|
229
|
-
* Style object for the button.
|
|
230
|
-
*/
|
|
231
|
-
style?: StyleProp<ViewStyle>;
|
|
232
232
|
};
|