@react-navigation/elements 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
Files changed (138) hide show
  1. package/lib/commonjs/Background.js +2 -2
  2. package/lib/commonjs/Background.js.map +1 -1
  3. package/lib/commonjs/Button.js +100 -0
  4. package/lib/commonjs/Button.js.map +1 -0
  5. package/lib/commonjs/Header/Header.js +8 -4
  6. package/lib/commonjs/Header/Header.js.map +1 -1
  7. package/lib/commonjs/Header/HeaderBackButton.js +17 -14
  8. package/lib/commonjs/Header/HeaderBackButton.js.map +1 -1
  9. package/lib/commonjs/Header/HeaderBackContext.js +1 -2
  10. package/lib/commonjs/Header/HeaderBackContext.js.map +1 -1
  11. package/lib/commonjs/Header/HeaderBackground.js +2 -2
  12. package/lib/commonjs/Header/HeaderBackground.js.map +1 -1
  13. package/lib/commonjs/Header/HeaderHeightContext.js +1 -2
  14. package/lib/commonjs/Header/HeaderHeightContext.js.map +1 -1
  15. package/lib/commonjs/Header/HeaderShownContext.js +1 -2
  16. package/lib/commonjs/Header/HeaderShownContext.js.map +1 -1
  17. package/lib/commonjs/Header/HeaderTitle.js +2 -2
  18. package/lib/commonjs/Header/HeaderTitle.js.map +1 -1
  19. package/lib/commonjs/Header/getDefaultHeaderHeight.js.map +1 -1
  20. package/lib/commonjs/Header/getHeaderTitle.js.map +1 -1
  21. package/lib/commonjs/Header/useHeaderHeight.js +2 -2
  22. package/lib/commonjs/Header/useHeaderHeight.js.map +1 -1
  23. package/lib/commonjs/Label/Label.js +6 -10
  24. package/lib/commonjs/Label/Label.js.map +1 -1
  25. package/lib/commonjs/Label/getLabel.js.map +1 -1
  26. package/lib/commonjs/MaskedView.android.js.map +1 -1
  27. package/lib/commonjs/MaskedView.ios.js.map +1 -1
  28. package/lib/commonjs/MaskedView.js.map +1 -1
  29. package/lib/commonjs/MaskedViewNative.js +3 -2
  30. package/lib/commonjs/MaskedViewNative.js.map +1 -1
  31. package/lib/commonjs/MissingIcon.js +2 -2
  32. package/lib/commonjs/MissingIcon.js.map +1 -1
  33. package/lib/commonjs/PlatformPressable.js +27 -4
  34. package/lib/commonjs/PlatformPressable.js.map +1 -1
  35. package/lib/commonjs/ResourceSavingView.js +2 -2
  36. package/lib/commonjs/ResourceSavingView.js.map +1 -1
  37. package/lib/commonjs/SafeAreaProviderCompat.js +2 -2
  38. package/lib/commonjs/SafeAreaProviderCompat.js.map +1 -1
  39. package/lib/commonjs/Screen.js +2 -2
  40. package/lib/commonjs/Screen.js.map +1 -1
  41. package/lib/commonjs/Text.js +28 -0
  42. package/lib/commonjs/Text.js.map +1 -0
  43. package/lib/commonjs/getDefaultSidebarWidth.js.map +1 -1
  44. package/lib/commonjs/getNamedContext.js +2 -2
  45. package/lib/commonjs/getNamedContext.js.map +1 -1
  46. package/lib/commonjs/index.js +18 -3
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/types.js.map +1 -1
  49. package/lib/module/Background.js.map +1 -1
  50. package/lib/module/Button.js +91 -0
  51. package/lib/module/Button.js.map +1 -0
  52. package/lib/module/Header/Header.js +6 -2
  53. package/lib/module/Header/Header.js.map +1 -1
  54. package/lib/module/Header/HeaderBackButton.js +15 -12
  55. package/lib/module/Header/HeaderBackButton.js.map +1 -1
  56. package/lib/module/Header/HeaderBackContext.js.map +1 -1
  57. package/lib/module/Header/HeaderBackground.js.map +1 -1
  58. package/lib/module/Header/HeaderHeightContext.js.map +1 -1
  59. package/lib/module/Header/HeaderShownContext.js.map +1 -1
  60. package/lib/module/Header/HeaderTitle.js.map +1 -1
  61. package/lib/module/Header/getDefaultHeaderHeight.js.map +1 -1
  62. package/lib/module/Header/getHeaderTitle.js.map +1 -1
  63. package/lib/module/Header/useHeaderHeight.js.map +1 -1
  64. package/lib/module/Label/Label.js +4 -8
  65. package/lib/module/Label/Label.js.map +1 -1
  66. package/lib/module/Label/getLabel.js.map +1 -1
  67. package/lib/module/MaskedView.android.js.map +1 -1
  68. package/lib/module/MaskedView.ios.js.map +1 -1
  69. package/lib/module/MaskedView.js.map +1 -1
  70. package/lib/module/MaskedViewNative.js +1 -0
  71. package/lib/module/MaskedViewNative.js.map +1 -1
  72. package/lib/module/MissingIcon.js.map +1 -1
  73. package/lib/module/PlatformPressable.js +25 -2
  74. package/lib/module/PlatformPressable.js.map +1 -1
  75. package/lib/module/ResourceSavingView.js.map +1 -1
  76. package/lib/module/SafeAreaProviderCompat.js.map +1 -1
  77. package/lib/module/Screen.js.map +1 -1
  78. package/lib/module/Text.js +20 -0
  79. package/lib/module/Text.js.map +1 -0
  80. package/lib/module/getDefaultSidebarWidth.js.map +1 -1
  81. package/lib/module/getNamedContext.js.map +1 -1
  82. package/lib/module/index.js +2 -0
  83. package/lib/module/index.js.map +1 -1
  84. package/lib/module/types.js.map +1 -1
  85. package/lib/typescript/src/Background.d.ts +2 -2
  86. package/lib/typescript/src/Background.d.ts.map +1 -1
  87. package/lib/typescript/src/Button.d.ts +12 -0
  88. package/lib/typescript/src/Button.d.ts.map +1 -0
  89. package/lib/typescript/src/Header/Header.d.ts +2 -1
  90. package/lib/typescript/src/Header/Header.d.ts.map +1 -1
  91. package/lib/typescript/src/Header/HeaderBackButton.d.ts +2 -1
  92. package/lib/typescript/src/Header/HeaderBackButton.d.ts.map +1 -1
  93. package/lib/typescript/src/Header/HeaderBackContext.d.ts +2 -1
  94. package/lib/typescript/src/Header/HeaderBackContext.d.ts.map +1 -1
  95. package/lib/typescript/src/Header/HeaderBackground.d.ts +2 -2
  96. package/lib/typescript/src/Header/HeaderBackground.d.ts.map +1 -1
  97. package/lib/typescript/src/Header/HeaderTitle.d.ts +3 -2
  98. package/lib/typescript/src/Header/HeaderTitle.d.ts.map +1 -1
  99. package/lib/typescript/src/Label/Label.d.ts +3 -2
  100. package/lib/typescript/src/Label/Label.d.ts.map +1 -1
  101. package/lib/typescript/src/MaskedViewNative.d.ts +1 -1
  102. package/lib/typescript/src/MaskedViewNative.d.ts.map +1 -1
  103. package/lib/typescript/src/MissingIcon.d.ts +3 -2
  104. package/lib/typescript/src/MissingIcon.d.ts.map +1 -1
  105. package/lib/typescript/src/PlatformPressable.d.ts +3 -2
  106. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
  107. package/lib/typescript/src/ResourceSavingView.d.ts +2 -2
  108. package/lib/typescript/src/ResourceSavingView.d.ts.map +1 -1
  109. package/lib/typescript/src/SafeAreaProviderCompat.d.ts +2 -2
  110. package/lib/typescript/src/SafeAreaProviderCompat.d.ts.map +1 -1
  111. package/lib/typescript/src/Screen.d.ts +3 -3
  112. package/lib/typescript/src/Screen.d.ts.map +1 -1
  113. package/lib/typescript/src/Text.d.ts +4 -0
  114. package/lib/typescript/src/Text.d.ts.map +1 -0
  115. package/lib/typescript/src/getNamedContext.d.ts.map +1 -1
  116. package/lib/typescript/src/index.d.ts +2 -0
  117. package/lib/typescript/src/index.d.ts.map +1 -1
  118. package/lib/typescript/src/types.d.ts +4 -0
  119. package/lib/typescript/src/types.d.ts.map +1 -1
  120. package/package.json +14 -12
  121. package/src/Background.tsx +6 -1
  122. package/src/Button.tsx +97 -0
  123. package/src/Header/Header.tsx +13 -3
  124. package/src/Header/HeaderBackButton.tsx +11 -8
  125. package/src/Header/HeaderBackContext.tsx +3 -4
  126. package/src/Header/HeaderBackground.tsx +3 -3
  127. package/src/Header/HeaderTitle.tsx +3 -3
  128. package/src/Label/Label.tsx +6 -13
  129. package/src/MaskedViewNative.tsx +1 -0
  130. package/src/MissingIcon.tsx +1 -1
  131. package/src/PlatformPressable.tsx +32 -4
  132. package/src/ResourceSavingView.tsx +7 -1
  133. package/src/SafeAreaProviderCompat.tsx +2 -2
  134. package/src/Screen.tsx +10 -4
  135. package/src/Text.tsx +14 -0
  136. package/src/getNamedContext.tsx +1 -0
  137. package/src/index.tsx +2 -0
  138. package/src/types.tsx +4 -0
@@ -1,13 +1,13 @@
1
- import { useTheme } from '@react-navigation/native';
2
1
  import * as React from 'react';
3
2
  import {
4
- StyleProp,
3
+ type StyleProp,
5
4
  StyleSheet,
6
- Text,
7
- TextProps,
8
- TextStyle,
5
+ type TextProps,
6
+ type TextStyle,
9
7
  } from 'react-native';
10
8
 
9
+ import { Text } from '../Text';
10
+
11
11
  type Props = Omit<TextProps, 'style'> & {
12
12
  tintColor?: string;
13
13
  children?: string;
@@ -15,18 +15,11 @@ type Props = Omit<TextProps, 'style'> & {
15
15
  };
16
16
 
17
17
  export function Label({ tintColor, style, ...rest }: Props) {
18
- const { colors, fonts } = useTheme();
19
-
20
18
  return (
21
19
  <Text
22
20
  numberOfLines={1}
23
21
  {...rest}
24
- style={[
25
- fonts.regular,
26
- styles.label,
27
- { color: tintColor === undefined ? colors.text : tintColor },
28
- style,
29
- ]}
22
+ style={[styles.label, tintColor != null && { color: tintColor }, style]}
30
23
  />
31
24
  );
32
25
  }
@@ -16,6 +16,7 @@ let RNCMaskedView: MaskedViewType | undefined;
16
16
  try {
17
17
  // Add try/catch to support usage even if it's not installed, since it's optional.
18
18
  // Newer versions of Metro will handle it properly.
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
19
20
  RNCMaskedView = require('@react-native-masked-view/masked-view').default;
20
21
  } catch (e) {
21
22
  // Ignore
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { StyleProp, StyleSheet, Text, TextStyle } from 'react-native';
2
+ import { type StyleProp, StyleSheet, Text, type TextStyle } from 'react-native';
3
3
 
4
4
  type Props = {
5
5
  color?: string;
@@ -3,18 +3,19 @@ import * as React from 'react';
3
3
  import {
4
4
  Animated,
5
5
  Easing,
6
- GestureResponderEvent,
6
+ type GestureResponderEvent,
7
7
  Platform,
8
8
  Pressable,
9
- PressableProps,
10
- StyleProp,
11
- ViewStyle,
9
+ type PressableProps,
10
+ type StyleProp,
11
+ type ViewStyle,
12
12
  } from 'react-native';
13
13
 
14
14
  export type Props = Omit<PressableProps, 'style'> & {
15
15
  pressColor?: string;
16
16
  pressOpacity?: number;
17
17
  style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
18
+ href?: string;
18
19
  children: React.ReactNode;
19
20
  };
20
21
 
@@ -28,6 +29,8 @@ const ANDROID_SUPPORTS_RIPPLE =
28
29
  * PlatformPressable provides an abstraction on top of Pressable to handle platform differences.
29
30
  */
30
31
  export function PlatformPressable({
32
+ disabled,
33
+ onPress,
31
34
  onPressIn,
32
35
  onPressOut,
33
36
  android_ripple,
@@ -52,6 +55,26 @@ export function PlatformPressable({
52
55
  }).start();
53
56
  };
54
57
 
58
+ const handlePress = (e: GestureResponderEvent) => {
59
+ // @ts-expect-error: these properties exist on web, but not in React Native
60
+ const hasModifierKey = e.metaKey || e.altKey || e.ctrlKey || e.shiftKey; // ignore clicks with modifier keys
61
+ // @ts-expect-error: these properties exist on web, but not in React Native
62
+ const isLeftClick = e.button == null || e.button === 0; // only handle left clicks
63
+ const isSelfTarget = [undefined, null, '', 'self'].includes(
64
+ // @ts-expect-error: these properties exist on web, but not in React Native
65
+ e.currentTarget?.target
66
+ ); // let browser handle "target=_blank" etc.
67
+
68
+ if (Platform.OS === 'web' && rest.href != null) {
69
+ if (!hasModifierKey && isLeftClick && isSelfTarget) {
70
+ e.preventDefault();
71
+ onPress?.(e);
72
+ }
73
+ } else {
74
+ onPress?.(e);
75
+ }
76
+ };
77
+
55
78
  const handlePressIn = (e: GestureResponderEvent) => {
56
79
  animateTo(pressOpacity, 0);
57
80
  onPressIn?.(e);
@@ -64,6 +87,11 @@ export function PlatformPressable({
64
87
 
65
88
  return (
66
89
  <AnimatedPressable
90
+ accessible
91
+ accessibilityRole={
92
+ Platform.OS === 'web' && rest.href != null ? 'link' : 'button'
93
+ }
94
+ onPress={disabled ? undefined : handlePress}
67
95
  onPressIn={handlePressIn}
68
96
  onPressOut={handlePressOut}
69
97
  android_ripple={
@@ -1,5 +1,11 @@
1
1
  import * as React from 'react';
2
- import { Platform, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
2
+ import {
3
+ Platform,
4
+ type StyleProp,
5
+ StyleSheet,
6
+ View,
7
+ type ViewStyle,
8
+ } from 'react-native';
3
9
 
4
10
  type Props = {
5
11
  visible: boolean;
@@ -2,10 +2,10 @@ import * as React from 'react';
2
2
  import {
3
3
  Dimensions,
4
4
  Platform,
5
- StyleProp,
5
+ type StyleProp,
6
6
  StyleSheet,
7
7
  View,
8
- ViewStyle,
8
+ type ViewStyle,
9
9
  } from 'react-native';
10
10
  import {
11
11
  initialWindowMetrics,
package/src/Screen.tsx CHANGED
@@ -1,12 +1,18 @@
1
1
  import {
2
2
  NavigationContext,
3
- NavigationProp,
3
+ type NavigationProp,
4
4
  NavigationRouteContext,
5
- ParamListBase,
6
- RouteProp,
5
+ type ParamListBase,
6
+ type RouteProp,
7
7
  } from '@react-navigation/native';
8
8
  import * as React from 'react';
9
- import { Animated, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
9
+ import {
10
+ Animated,
11
+ type StyleProp,
12
+ StyleSheet,
13
+ View,
14
+ type ViewStyle,
15
+ } from 'react-native';
10
16
  import {
11
17
  useSafeAreaFrame,
12
18
  useSafeAreaInsets,
package/src/Text.tsx ADDED
@@ -0,0 +1,14 @@
1
+ import { useTheme } from '@react-navigation/native';
2
+ import * as React from 'react';
3
+ import { Text as NativeText, type TextProps } from 'react-native';
4
+
5
+ export function Text({ style, ...rest }: TextProps) {
6
+ const { colors, fonts } = useTheme();
7
+
8
+ return (
9
+ <NativeText
10
+ {...rest}
11
+ style={[{ color: colors.text }, fonts.regular, style]}
12
+ />
13
+ );
14
+ }
@@ -3,6 +3,7 @@ import * as React from 'react';
3
3
  const contexts = '__react_navigation__elements_contexts';
4
4
 
5
5
  declare global {
6
+ // eslint-disable-next-line no-var
6
7
  var __react_navigation__elements_contexts: Map<string, React.Context<any>>;
7
8
  }
8
9
 
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Background } from './Background';
2
+ export { Button } from './Button';
2
3
  export { getDefaultSidebarWidth } from './getDefaultSidebarWidth';
3
4
  export { getDefaultHeaderHeight } from './Header/getDefaultHeaderHeight';
4
5
  export { getHeaderTitle } from './Header/getHeaderTitle';
@@ -17,6 +18,7 @@ export { PlatformPressable } from './PlatformPressable';
17
18
  export { ResourceSavingView } from './ResourceSavingView';
18
19
  export { SafeAreaProviderCompat } from './SafeAreaProviderCompat';
19
20
  export { Screen } from './Screen';
21
+ export { Text } from './Text';
20
22
 
21
23
  export const Assets = [
22
24
  // eslint-disable-next-line import/no-commonjs
package/src/types.tsx CHANGED
@@ -179,6 +179,10 @@ export type HeaderBackButtonProps = HeaderButtonProps & {
179
179
  * Function which returns a React Element to display custom image in header's back button.
180
180
  */
181
181
  backImage?: (props: { tintColor: string }) => React.ReactNode;
182
+ /**
183
+ * The `href` to use for the anchor tag on web
184
+ */
185
+ href?: string;
182
186
  /**
183
187
  * Label text for the button. Usually the title of the previous screen.
184
188
  * By default, this is only shown on iOS.