@expo/html-elements 0.12.2 → 0.12.4

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 (149) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/css/createSafeStyledView.native.d.ts +1 -1
  3. package/build/css/createSafeStyledView.native.d.ts.map +1 -1
  4. package/build/elements/Anchor.d.ts +2 -2
  5. package/build/elements/Anchor.d.ts.map +1 -1
  6. package/build/elements/Headings.d.ts.map +1 -1
  7. package/build/elements/Layout.d.ts.map +1 -1
  8. package/build/elements/Lists.d.ts +2 -2
  9. package/build/elements/Lists.d.ts.map +1 -1
  10. package/build/elements/Rules.d.ts +2 -2
  11. package/build/elements/Rules.d.ts.map +1 -1
  12. package/build/elements/Rules.web.d.ts +1 -2
  13. package/build/elements/Rules.web.d.ts.map +1 -1
  14. package/build/elements/Table.d.ts +9 -9
  15. package/build/elements/Table.d.ts.map +1 -1
  16. package/build/elements/Table.web.d.ts.map +1 -1
  17. package/build/elements/Text.d.ts +15 -15
  18. package/build/elements/Text.d.ts.map +1 -1
  19. package/build/primitives/RNWView.d.ts +4 -2
  20. package/build/primitives/RNWView.d.ts.map +1 -1
  21. package/build/primitives/createDevView.d.ts +1 -1
  22. package/build/primitives/createDevView.d.ts.map +1 -1
  23. package/jest-setup.js +1 -0
  24. package/package.json +13 -7
  25. package/{build/Elements.js → src/Elements.tsx} +0 -1
  26. package/src/css/__tests__/__snapshots__/createSafeStyledView.test.native.tsx.snap.android +31 -0
  27. package/src/css/__tests__/__snapshots__/createSafeStyledView.test.native.tsx.snap.ios +31 -0
  28. package/src/css/__tests__/createSafeStyledView.test.native.tsx +54 -0
  29. package/src/css/createSafeStyledView.native.tsx +12 -0
  30. package/src/css/createSafeStyledView.tsx +4 -0
  31. package/src/css/filterStyles.ts +92 -0
  32. package/src/css/units.ts +11 -0
  33. package/src/elements/Anchor.tsx +27 -0
  34. package/src/elements/Headings.tsx +81 -0
  35. package/src/elements/Layout.tsx +72 -0
  36. package/src/elements/Lists.tsx +45 -0
  37. package/src/elements/Rules.tsx +18 -0
  38. package/src/elements/Rules.web.tsx +7 -0
  39. package/src/elements/Table.tsx +59 -0
  40. package/src/elements/Table.web.tsx +38 -0
  41. package/src/elements/Text.tsx +111 -0
  42. package/src/elements/Text.types.ts +21 -0
  43. package/src/elements/__tests__/Anchor.test.ios.tsx +10 -0
  44. package/src/elements/__tests__/Anchor.test.web.tsx +11 -0
  45. package/src/elements/__tests__/Headings.test.ios.tsx +13 -0
  46. package/src/elements/__tests__/Layout.test.ios.tsx +40 -0
  47. package/src/elements/__tests__/Layout.test.web.tsx +50 -0
  48. package/src/elements/__tests__/Lists.test.native.tsx +17 -0
  49. package/src/elements/__tests__/Lists.test.web.tsx +41 -0
  50. package/src/elements/__tests__/Rules.test.native.tsx +10 -0
  51. package/src/elements/__tests__/Rules.test.web.tsx +8 -0
  52. package/src/elements/__tests__/Table.test.ios.tsx +45 -0
  53. package/src/elements/__tests__/Table.test.web.tsx +49 -0
  54. package/src/elements/__tests__/Text.test.ios.tsx +102 -0
  55. package/src/elements/__tests__/__snapshots__/Anchor-test.tsx.snap.android +8 -0
  56. package/src/elements/__tests__/__snapshots__/Anchor-test.tsx.snap.ios +8 -0
  57. package/src/elements/__tests__/__snapshots__/Anchor-test.tsx.snap.web +12 -0
  58. package/src/elements/__tests__/__snapshots__/Anchor.test.ios.tsx.snap.ios +8 -0
  59. package/src/elements/__tests__/__snapshots__/Anchor.test.tsx.snap.android +8 -0
  60. package/src/elements/__tests__/__snapshots__/Anchor.test.tsx.snap.ios +8 -0
  61. package/src/elements/__tests__/__snapshots__/Anchor.test.tsx.snap.web +12 -0
  62. package/src/elements/__tests__/__snapshots__/Headings-test.tsx.snap.android +79 -0
  63. package/src/elements/__tests__/__snapshots__/Headings-test.tsx.snap.ios +79 -0
  64. package/src/elements/__tests__/__snapshots__/Headings-test.tsx.snap.web +61 -0
  65. package/src/elements/__tests__/__snapshots__/Headings.test.ios.tsx.snap.ios +79 -0
  66. package/src/elements/__tests__/__snapshots__/Layout-test.tsx.snap.android +23 -0
  67. package/src/elements/__tests__/__snapshots__/Layout-test.tsx.snap.ios +23 -0
  68. package/src/elements/__tests__/__snapshots__/Layout-test.tsx.snap.web +64 -0
  69. package/src/elements/__tests__/__snapshots__/Layout.test.ios.tsx.snap.ios +23 -0
  70. package/src/elements/__tests__/__snapshots__/Layout.test.tsx.snap.android +23 -0
  71. package/src/elements/__tests__/__snapshots__/Layout.test.tsx.snap.ios +23 -0
  72. package/src/elements/__tests__/__snapshots__/Layout.test.tsx.snap.web +64 -0
  73. package/src/elements/__tests__/__snapshots__/Lists-test.tsx.snap.android +14 -0
  74. package/src/elements/__tests__/__snapshots__/Lists-test.tsx.snap.ios +14 -0
  75. package/src/elements/__tests__/__snapshots__/Lists-test.tsx.snap.web +34 -0
  76. package/src/elements/__tests__/__snapshots__/Lists.test.native.tsx.snap.android +14 -0
  77. package/src/elements/__tests__/__snapshots__/Lists.test.native.tsx.snap.ios +14 -0
  78. package/src/elements/__tests__/__snapshots__/Rules-test.tsx.snap.android +15 -0
  79. package/src/elements/__tests__/__snapshots__/Rules-test.tsx.snap.ios +15 -0
  80. package/src/elements/__tests__/__snapshots__/Rules-test.tsx.snap.web +7 -0
  81. package/src/elements/__tests__/__snapshots__/Rules.test.native.tsx.snap.android +15 -0
  82. package/src/elements/__tests__/__snapshots__/Rules.test.native.tsx.snap.ios +15 -0
  83. package/src/elements/__tests__/__snapshots__/Table-test.tsx.snap.android +60 -0
  84. package/src/elements/__tests__/__snapshots__/Table-test.tsx.snap.ios +60 -0
  85. package/src/elements/__tests__/__snapshots__/Table-test.tsx.snap.web +71 -0
  86. package/src/elements/__tests__/__snapshots__/Table.test.ios.tsx.snap.ios +60 -0
  87. package/src/elements/__tests__/__snapshots__/Table.test.tsx.snap.android +60 -0
  88. package/src/elements/__tests__/__snapshots__/Table.test.tsx.snap.ios +60 -0
  89. package/src/elements/__tests__/__snapshots__/Table.test.tsx.snap.web +71 -0
  90. package/src/elements/__tests__/__snapshots__/Text-test.tsx.snap.android +174 -0
  91. package/src/elements/__tests__/__snapshots__/Text-test.tsx.snap.ios +174 -0
  92. package/src/elements/__tests__/__snapshots__/Text-test.tsx.snap.web +149 -0
  93. package/src/elements/__tests__/__snapshots__/Text.test.ios.tsx.snap.ios +174 -0
  94. package/src/primitives/Image.tsx +30 -0
  95. package/src/primitives/RNWView.tsx +178 -0
  96. package/src/primitives/Table.ts +14 -0
  97. package/src/primitives/Text.tsx +68 -0
  98. package/src/primitives/View.tsx +145 -0
  99. package/src/primitives/__tests__/__snapshots__/createDevView.test.ios.tsx.snap.ios +35 -0
  100. package/src/primitives/__tests__/__snapshots__/createDevView.test.tsx.snap.android +35 -0
  101. package/src/primitives/__tests__/__snapshots__/createDevView.test.tsx.snap.ios +35 -0
  102. package/src/primitives/__tests__/__snapshots__/createDevView.test.tsx.snap.web +30 -0
  103. package/src/primitives/__tests__/__snapshots__/createDevView.test.web.tsx.snap.web +27 -0
  104. package/src/primitives/__tests__/createDevView.test.tsx +53 -0
  105. package/src/primitives/createDevView.tsx +48 -0
  106. package/src/ts-declarations/process.d.ts +7 -0
  107. package/src/ts-declarations/react-native-web.d.ts +1016 -0
  108. package/tsconfig.json +2 -2
  109. package/build/Elements.js.map +0 -1
  110. package/build/css/createSafeStyledView.js +0 -5
  111. package/build/css/createSafeStyledView.js.map +0 -1
  112. package/build/css/createSafeStyledView.native.js +0 -10
  113. package/build/css/createSafeStyledView.native.js.map +0 -1
  114. package/build/css/filterStyles.js +0 -83
  115. package/build/css/filterStyles.js.map +0 -1
  116. package/build/css/units.js +0 -12
  117. package/build/css/units.js.map +0 -1
  118. package/build/elements/Anchor.js +0 -25
  119. package/build/elements/Anchor.js.map +0 -1
  120. package/build/elements/Headings.js +0 -78
  121. package/build/elements/Headings.js.map +0 -1
  122. package/build/elements/Layout.js +0 -46
  123. package/build/elements/Layout.js.map +0 -1
  124. package/build/elements/Lists.js +0 -33
  125. package/build/elements/Lists.js.map +0 -1
  126. package/build/elements/Rules.js +0 -16
  127. package/build/elements/Rules.js.map +0 -1
  128. package/build/elements/Rules.web.js +0 -6
  129. package/build/elements/Rules.web.js.map +0 -1
  130. package/build/elements/Table.js +0 -50
  131. package/build/elements/Table.js.map +0 -1
  132. package/build/elements/Table.web.js +0 -27
  133. package/build/elements/Table.web.js.map +0 -1
  134. package/build/elements/Text.js +0 -92
  135. package/build/elements/Text.js.map +0 -1
  136. package/build/elements/Text.types.js +0 -2
  137. package/build/elements/Text.types.js.map +0 -1
  138. package/build/primitives/Image.js +0 -5
  139. package/build/primitives/Image.js.map +0 -1
  140. package/build/primitives/RNWView.js +0 -122
  141. package/build/primitives/RNWView.js.map +0 -1
  142. package/build/primitives/Table.js +0 -3
  143. package/build/primitives/Table.js.map +0 -1
  144. package/build/primitives/Text.js +0 -5
  145. package/build/primitives/Text.js.map +0 -1
  146. package/build/primitives/View.js +0 -10
  147. package/build/primitives/View.js.map +0 -1
  148. package/build/primitives/createDevView.js +0 -43
  149. package/build/primitives/createDevView.js.map +0 -1
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Copyright (c) Expo.
3
+ * Copyright (c) Nicolas Gallagher.
4
+ * Copyright (c) Facebook, Inc. and its affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import * as React from 'react';
10
+ import StyleSheet from 'react-native-web/dist/exports/StyleSheet';
11
+ import TextAncestorContext from 'react-native-web/dist/exports/Text/TextAncestorContext';
12
+ import { ViewProps } from 'react-native-web/dist/exports/View/types';
13
+ import createElement from 'react-native-web/dist/exports/createElement';
14
+ import * as forwardedProps from 'react-native-web/dist/modules/forwardedProps';
15
+ import pick from 'react-native-web/dist/modules/pick';
16
+ import useElementLayout from 'react-native-web/dist/modules/useElementLayout';
17
+ import { useLocaleContext, getLocaleDirection } from 'react-native-web/dist/modules/useLocale';
18
+ import useMergeRefs from 'react-native-web/dist/modules/useMergeRefs';
19
+ import usePlatformMethods from 'react-native-web/dist/modules/usePlatformMethods';
20
+ import useResponderEvents from 'react-native-web/dist/modules/useResponderEvents';
21
+
22
+ const forwardPropsList = Object.assign(
23
+ {},
24
+ forwardedProps.defaultProps,
25
+ forwardedProps.accessibilityProps,
26
+ forwardedProps.clickProps,
27
+ forwardedProps.defaultProps,
28
+ forwardedProps.accessibilityProps,
29
+ forwardedProps.clickProps,
30
+ forwardedProps.focusProps,
31
+ forwardedProps.keyboardProps,
32
+ forwardedProps.mouseProps,
33
+ forwardedProps.touchProps,
34
+ forwardedProps.styleProps,
35
+ {
36
+ href: true,
37
+ lang: true,
38
+ onScroll: true,
39
+ onWheel: true,
40
+ pointerEvents: true,
41
+ }
42
+ );
43
+
44
+ function pickProps(props: React.ComponentProps<any>) {
45
+ return pick(props, forwardPropsList);
46
+ }
47
+
48
+ /**
49
+ * This is the View from react-native-web copied out in order to supply a custom `__element` property.
50
+ * In the past, you could use `createElement` to create an element with a custom HTML element, but this changed
51
+ * somewhere between 0.14...0.17.
52
+ */
53
+
54
+ function View(props: ViewProps) {
55
+ const {
56
+ __element,
57
+ hrefAttrs,
58
+ onLayout,
59
+ onMoveShouldSetResponder,
60
+ onMoveShouldSetResponderCapture,
61
+ onResponderEnd,
62
+ onResponderGrant,
63
+ onResponderMove,
64
+ onResponderReject,
65
+ onResponderRelease,
66
+ onResponderStart,
67
+ onResponderTerminate,
68
+ onResponderTerminationRequest,
69
+ onScrollShouldSetResponder,
70
+ onScrollShouldSetResponderCapture,
71
+ onSelectionChangeShouldSetResponder,
72
+ onSelectionChangeShouldSetResponderCapture,
73
+ onStartShouldSetResponder,
74
+ onStartShouldSetResponderCapture,
75
+ ref: forwardedRef,
76
+ ...rest
77
+ } = props as any;
78
+
79
+ // if (process.env.NODE_ENV !== 'production') {
80
+ // React.Children.toArray(props.children).forEach((item) => {
81
+ // if (typeof item === 'string') {
82
+ // console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`);
83
+ // }
84
+ // });
85
+ // }
86
+
87
+ const hasTextAncestor = React.use(TextAncestorContext);
88
+ const hostRef = React.useRef(null);
89
+ const { direction: contextDirection } = useLocaleContext();
90
+
91
+ useElementLayout(hostRef, onLayout);
92
+ useResponderEvents(hostRef, {
93
+ onMoveShouldSetResponder,
94
+ onMoveShouldSetResponderCapture,
95
+ onResponderEnd,
96
+ onResponderGrant,
97
+ onResponderMove,
98
+ onResponderReject,
99
+ onResponderRelease,
100
+ onResponderStart,
101
+ onResponderTerminate,
102
+ onResponderTerminationRequest,
103
+ onScrollShouldSetResponder,
104
+ onScrollShouldSetResponderCapture,
105
+ onSelectionChangeShouldSetResponder,
106
+ onSelectionChangeShouldSetResponderCapture,
107
+ onStartShouldSetResponder,
108
+ onStartShouldSetResponderCapture,
109
+ });
110
+
111
+ let component = __element ?? 'div';
112
+
113
+ const langDirection = props.lang != null ? getLocaleDirection(props.lang) : null;
114
+ const componentDirection = props.dir || langDirection;
115
+ const writingDirection = componentDirection || contextDirection;
116
+
117
+ const supportedProps = pickProps(rest);
118
+ supportedProps.dir = componentDirection;
119
+ supportedProps.style = [styles.view$raw, hasTextAncestor && styles.inline, props.style];
120
+ if (props.href != null) {
121
+ component = 'a';
122
+ if (hrefAttrs != null) {
123
+ const { download, rel, target } = hrefAttrs;
124
+ if (download != null) {
125
+ supportedProps.download = download;
126
+ }
127
+ if (rel != null) {
128
+ supportedProps.rel = rel;
129
+ }
130
+ if (typeof target === 'string') {
131
+ supportedProps.target = target.charAt(0) !== '_' ? '_' + target : target;
132
+ }
133
+ }
134
+ }
135
+
136
+ const platformMethodsRef = usePlatformMethods(supportedProps);
137
+ const setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef);
138
+
139
+ return createElement(
140
+ component,
141
+ {
142
+ ...supportedProps,
143
+ ref: setRef,
144
+ },
145
+ // @ts-expect-error TODO(cedric): 'writingDirection' does not exist in type 'ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>'
146
+ { writingDirection }
147
+ );
148
+ }
149
+
150
+ if (__DEV__) {
151
+ View.displayName = 'View';
152
+ }
153
+
154
+ const styles = StyleSheet.create({
155
+ view$raw: {
156
+ alignItems: 'stretch',
157
+ backgroundColor: 'transparent',
158
+ border: '0 solid black',
159
+ boxSizing: 'border-box',
160
+ display: 'flex',
161
+ flexBasis: 'auto',
162
+ flexDirection: 'column',
163
+ flexShrink: 0,
164
+ listStyle: 'none',
165
+ margin: 0,
166
+ minHeight: 0,
167
+ minWidth: 0,
168
+ padding: 0,
169
+ position: 'relative',
170
+ textDecoration: 'none',
171
+ zIndex: 0,
172
+ },
173
+ inline: {
174
+ display: 'inline-flex',
175
+ },
176
+ });
177
+
178
+ export default View;
@@ -0,0 +1,14 @@
1
+ import { ClassAttributes, ComponentProps, ComponentType } from 'react';
2
+
3
+ import Text from './Text';
4
+
5
+ type NativeTextProps = ComponentProps<typeof Text> & ClassAttributes<typeof Text>;
6
+
7
+ export type TableTextProps = NativeTextProps & {
8
+ /** @platform web */
9
+ colSpan?: number | string;
10
+ /** @platform web */
11
+ rowSpan?: number | string;
12
+ };
13
+
14
+ export const TableText = Text as ComponentType<TableTextProps>;
@@ -0,0 +1,68 @@
1
+ import { ClassAttributes, ComponentProps, ComponentType } from 'react';
2
+ import { StyleProp, Text as NativeText, TextStyle as NativeTextStyle } from 'react-native';
3
+
4
+ import { WebViewStyle } from './View';
5
+ import { createSafeStyledView } from '../css/createSafeStyledView';
6
+
7
+ // https://github.com/necolas/react-native-web/issues/832
8
+
9
+ type NativeTextProps = ComponentProps<typeof NativeText> & ClassAttributes<typeof NativeText>;
10
+
11
+ export interface WebTextStyle {
12
+ /** string is only available on web */
13
+ fontSize?: NativeTextStyle['fontSize'] | string;
14
+ /** string is only available on web */
15
+ lineHeight?: NativeTextStyle['lineHeight'] | string;
16
+ /** @platform web */
17
+ fontFeatureSettings?: string;
18
+ /** @platform web */
19
+ textIndent?: string;
20
+ /** @platform web */
21
+ textOverflow?: string;
22
+ /** @platform web */
23
+ textRendering?: string;
24
+ /** @platform web */
25
+ textTransform?: string;
26
+ /** @platform web */
27
+ unicodeBidi?: string;
28
+ /** @platform web */
29
+ wordWrap?: string;
30
+ }
31
+
32
+ export type TextStyle = Omit<NativeTextStyle, 'position' | 'fontSize' | 'lineHeight'> &
33
+ WebTextStyle &
34
+ WebViewStyle;
35
+
36
+ export type WebTextProps = {
37
+ style?: StyleProp<TextStyle>;
38
+ /** @platform web */
39
+ tabIndex?: number;
40
+ /** @platform web */
41
+ 'aria-level'?: number;
42
+ /**
43
+ * @deprecated use `aria-level` instead.
44
+ * @platform web
45
+ */
46
+ accessibilityLevel?: number;
47
+ /** @platform web */
48
+ href?: string;
49
+ /** @deprecated use the prop `hrefAttrs={{ target: '...' }}` instead. */
50
+ target?: string;
51
+ /** @platform web */
52
+ hrefAttrs?: {
53
+ /** @platform web */
54
+ target?: string;
55
+ /** @platform web */
56
+ rel?: string;
57
+ /** @platform web */
58
+ download?: boolean | string;
59
+ };
60
+ /** @platform web */
61
+ lang?: string;
62
+ };
63
+
64
+ export type TextProps = Omit<NativeTextProps, 'style'> & WebTextProps;
65
+
66
+ const Text = NativeText as ComponentType<TextProps>;
67
+
68
+ export default createSafeStyledView(Text) as ComponentType<TextProps>;
@@ -0,0 +1,145 @@
1
+ import { ClassAttributes, ComponentProps, ComponentType } from 'react';
2
+ import {
3
+ StyleProp,
4
+ View as NativeView,
5
+ ViewStyle as NativeViewStyle,
6
+ BoxShadowValue,
7
+ FilterFunction,
8
+ type ColorValue,
9
+ } from 'react-native';
10
+
11
+ import { createDevView } from './createDevView';
12
+ import { createSafeStyledView } from '../css/createSafeStyledView';
13
+
14
+ // https://github.com/necolas/react-native-web/issues/832
15
+
16
+ type NativeViewProps = ComponentProps<typeof NativeView> & ClassAttributes<typeof NativeView>;
17
+
18
+ /**
19
+ * https://baconbrix.gitbook.io/react-native-web/primitives/view
20
+ */
21
+ export interface WebViewStyle {
22
+ /** @platform web */
23
+ backdropFilter?: string;
24
+ /** @platform web */
25
+ animationDelay?: string;
26
+ /** @platform web */
27
+ animationDirection?: string;
28
+ /** @platform web */
29
+ animationDuration?: string;
30
+ /** @platform web */
31
+ animationFillMode?: string;
32
+ /** @platform web */
33
+ animationName?: string | any[];
34
+ /** @platform web */
35
+ animationIterationCount?: number | 'infinite';
36
+ /** @platform web */
37
+ animationPlayState?: string;
38
+ /** @platform web */
39
+ animationTimingFunction?: string;
40
+ /** @platform web */
41
+ backgroundAttachment?: string;
42
+ /** @platform web */
43
+ backgroundBlendMode?: string;
44
+ /** @platform web */
45
+ backgroundClip?: string;
46
+ /** @platform web */
47
+ backgroundImage?: string;
48
+ /** @platform web */
49
+ backgroundOrigin?: 'border-box' | 'content-box' | 'padding-box';
50
+ /** @platform web */
51
+ backgroundPosition?: string;
52
+ /** @platform web */
53
+ backgroundRepeat?: string;
54
+ /** @platform web */
55
+ backgroundSize?: string;
56
+ /** @platform web */
57
+ boxShadow?: string | readonly BoxShadowValue[];
58
+ /** @platform web */
59
+ boxSizing?: string;
60
+ /** @platform web */
61
+ clip?: string;
62
+ /** @platform web */
63
+ cursor?: string;
64
+ /** @platform web */
65
+ filter?: string | readonly FilterFunction[];
66
+ /** @platform web */
67
+ gridAutoColumns?: string;
68
+ /** @platform web */
69
+ gridAutoFlow?: string;
70
+ /** @platform web */
71
+ gridAutoRows?: string;
72
+ /** @platform web */
73
+ gridColumnEnd?: string;
74
+ /** @platform web */
75
+ gridColumnGap?: string;
76
+ /** @platform web */
77
+ gridColumnStart?: string;
78
+ /** @platform web */
79
+ gridRowEnd?: string;
80
+ /** @platform web */
81
+ gridRowGap?: string;
82
+ /** @platform web */
83
+ gridRowStart?: string;
84
+ /** @platform web */
85
+ gridTemplateColumns?: string;
86
+ /** @platform web */
87
+ gridTemplateRows?: string;
88
+ /** @platform web */
89
+ gridTemplateAreas?: string;
90
+ /** @platform web */
91
+ outline?: string;
92
+ /** @platform web */
93
+ outlineColor?: ColorValue;
94
+ /** @platform web */
95
+ overflowX?: string;
96
+ /** @platform web */
97
+ overflowY?: string;
98
+ /** @platform web */
99
+ overscrollBehavior?: 'auto' | 'contain' | 'none';
100
+ /** @platform web */
101
+ overscrollBehaviorX?: 'auto' | 'contain' | 'none';
102
+ /** @platform web */
103
+ overscrollBehaviorY?: 'auto' | 'contain' | 'none';
104
+ /** @platform web */
105
+ perspective?: string;
106
+ /** @platform web */
107
+ perspectiveOrigin?: string;
108
+ /** @platform web */
109
+ touchAction?: string;
110
+ /** @platform web */
111
+ transformOrigin?: string | (string | number)[];
112
+ /** @platform web */
113
+ transitionDelay?: string;
114
+ /** @platform web */
115
+ transitionDuration?: string;
116
+ /** @platform web */
117
+ transitionProperty?: string;
118
+ /** @platform web */
119
+ transitionTimingFunction?: string;
120
+ /** @platform web */
121
+ userSelect?: string;
122
+ /** @platform web */
123
+ visibility?: string;
124
+ /** @platform web */
125
+ willChange?: string;
126
+ /** @platform web */
127
+ position?: 'static' | 'relative' | 'absolute' | 'fixed' | 'sticky';
128
+ }
129
+
130
+ export type ViewStyle = Omit<NativeViewStyle, 'position'> & WebViewStyle;
131
+
132
+ export type WebViewProps = {
133
+ style?: StyleProp<ViewStyle>;
134
+ };
135
+
136
+ export type ViewProps = WebViewProps & Omit<NativeViewProps, 'style'>;
137
+
138
+ let View = NativeView as ComponentType<ViewProps>;
139
+
140
+ if (process.env.NODE_ENV !== 'production') {
141
+ // Add better errors and warnings in development builds.
142
+ View = createDevView(NativeView) as ComponentType<ViewProps>;
143
+ }
144
+
145
+ export default createSafeStyledView(View) as ComponentType<ViewProps>;
@@ -0,0 +1,35 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`warns about unwrapped strings 1`] = `
4
+ <View>
5
+ <Text
6
+ style={
7
+ [
8
+ {
9
+ "bottom": 0,
10
+ "left": 0,
11
+ "position": "absolute",
12
+ "right": 0,
13
+ "top": 0,
14
+ },
15
+ {
16
+ "backgroundColor": "firebrick",
17
+ "color": "white",
18
+ },
19
+ ]
20
+ }
21
+ >
22
+ Unwrapped text: "
23
+ <Text
24
+ style={
25
+ {
26
+ "fontWeight": "bold",
27
+ }
28
+ }
29
+ >
30
+ Hey
31
+ </Text>
32
+ "
33
+ </Text>
34
+ </View>
35
+ `;
@@ -0,0 +1,35 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`warns about unwrapped strings 1`] = `
4
+ <View>
5
+ <Text
6
+ style={
7
+ [
8
+ {
9
+ "bottom": 0,
10
+ "left": 0,
11
+ "position": "absolute",
12
+ "right": 0,
13
+ "top": 0,
14
+ },
15
+ {
16
+ "backgroundColor": "firebrick",
17
+ "color": "white",
18
+ },
19
+ ]
20
+ }
21
+ >
22
+ Unwrapped text: "
23
+ <Text
24
+ style={
25
+ {
26
+ "fontWeight": "bold",
27
+ }
28
+ }
29
+ >
30
+ Hey
31
+ </Text>
32
+ "
33
+ </Text>
34
+ </View>
35
+ `;
@@ -0,0 +1,35 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`warns about unwrapped strings 1`] = `
4
+ <View>
5
+ <Text
6
+ style={
7
+ [
8
+ {
9
+ "bottom": 0,
10
+ "left": 0,
11
+ "position": "absolute",
12
+ "right": 0,
13
+ "top": 0,
14
+ },
15
+ {
16
+ "backgroundColor": "firebrick",
17
+ "color": "white",
18
+ },
19
+ ]
20
+ }
21
+ >
22
+ Unwrapped text: "
23
+ <Text
24
+ style={
25
+ {
26
+ "fontWeight": "bold",
27
+ }
28
+ }
29
+ >
30
+ Hey
31
+ </Text>
32
+ "
33
+ </Text>
34
+ </View>
35
+ `;
@@ -0,0 +1,30 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`warns about unwrapped strings 1`] = `
4
+ <div
5
+ className="css-view-g5y9jx"
6
+ dir={null}
7
+ ref={[Function]}
8
+ >
9
+ <div
10
+ className="css-text-146c3p1 r-bottom-1p0dtai r-left-1d2f490 r-position-u8s1d r-right-zchlnj r-top-ipm5af r-backgroundColor-1kfbv51 r-color-jwli3a"
11
+ dir="auto"
12
+ ref={[Function]}
13
+ >
14
+ Unwrapped text: "
15
+ <span
16
+ className="css-textHasAncestor-1jxf684"
17
+ dir={null}
18
+ ref={[Function]}
19
+ style={
20
+ {
21
+ "fontWeight": "bold",
22
+ }
23
+ }
24
+ >
25
+ Hey
26
+ </span>
27
+ "
28
+ </div>
29
+ </div>
30
+ `;
@@ -0,0 +1,27 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`warns about unwrapped strings 1`] = `
4
+ <div
5
+ className="css-view-175oi2r"
6
+ dir={null}
7
+ >
8
+ <div
9
+ className="css-text-1rynq56 r-bottom-1p0dtai r-left-1d2f490 r-position-u8s1d r-right-zchlnj r-top-ipm5af r-backgroundColor-1kfbv51 r-color-jwli3a"
10
+ dir="auto"
11
+ >
12
+ Unwrapped text: "
13
+ <span
14
+ className="css-textHasAncestor-1qaijid"
15
+ dir={null}
16
+ style={
17
+ {
18
+ "fontWeight": "bold",
19
+ }
20
+ }
21
+ >
22
+ Hey
23
+ </span>
24
+ "
25
+ </div>
26
+ </div>
27
+ `;
@@ -0,0 +1,53 @@
1
+ import { render } from '@testing-library/react-native';
2
+ import * as React from 'react';
3
+ import { Platform, View as NativeView } from 'react-native';
4
+
5
+ import { createDevView } from '../createDevView';
6
+
7
+ export const View = createDevView(NativeView);
8
+
9
+ const originalConsoleError = console.error;
10
+ const originalConsoleWarn = console.warn;
11
+
12
+ beforeEach(() => {
13
+ console.error = jest.fn();
14
+ console.warn = jest.fn();
15
+ });
16
+ afterAll(() => {
17
+ console.error = originalConsoleError;
18
+ console.warn = originalConsoleWarn;
19
+ });
20
+
21
+ it('renders', () => {
22
+ // Ensure no errors
23
+ expect(() =>
24
+ render(
25
+ <View>
26
+ <View />
27
+ </View>
28
+ )
29
+ ).not.toThrow();
30
+ });
31
+
32
+ it('asserts react-dom elements', () => {
33
+ const instance = (
34
+ <View>
35
+ <div />
36
+ </View>
37
+ );
38
+
39
+ if (Platform.OS === 'web') {
40
+ // Ensure no errors
41
+ expect(() => render(instance)).not.toThrow();
42
+ } else {
43
+ expect(() => render(instance)).toThrow(/Using unsupported React DOM element/);
44
+ }
45
+ });
46
+
47
+ it('warns about unwrapped strings', () => {
48
+ // Ensure no errors
49
+ const { toJSON } = render(<View>Hey</View>);
50
+ expect(toJSON()).toMatchSnapshot();
51
+
52
+ expect(console.warn).toHaveBeenCalledTimes(1);
53
+ });
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { Platform, StyleSheet, Text } from 'react-native';
3
+
4
+ function useChildren(inputChildren: React.ReactNode) {
5
+ return React.useMemo(() => {
6
+ const children: React.ReactNode[] = [];
7
+ React.Children.forEach(inputChildren, (child) => {
8
+ if (child == null || typeof child === 'boolean') {
9
+ } else if (
10
+ typeof child === 'string' ||
11
+ typeof child === 'number' ||
12
+ typeof child === 'bigint'
13
+ ) {
14
+ // Wrap text in a Text component.
15
+ let message = `Invalid raw text as a child of View: "${child}"${
16
+ child === '' ? ` [empty string]` : ''
17
+ }.`;
18
+ message += ' Wrap the text contents with a Text element or remove it.';
19
+ console.warn(message);
20
+ children.push(
21
+ <Text style={[StyleSheet.absoluteFill, styles.error]}>
22
+ Unwrapped text: "<Text style={{ fontWeight: 'bold' }}>{child}</Text>"
23
+ </Text>
24
+ );
25
+ } else if ('type' in child && typeof child?.type === 'string' && Platform.OS !== 'web') {
26
+ // Disallow untransformed react-dom elements on native.
27
+ throw new Error(`Using unsupported React DOM element: <${child.type} />`);
28
+ } else {
29
+ children.push(child);
30
+ }
31
+ });
32
+ return children;
33
+ }, [inputChildren]);
34
+ }
35
+
36
+ /** Extend a view with a `children` filter that asserts more helpful warnings/errors. */
37
+ export function createDevView<TView extends React.ComponentType<any>>(View: TView) {
38
+ return function DevView({ children, ...props }: any) {
39
+ return <View {...props} children={useChildren(children)} />;
40
+ };
41
+ }
42
+
43
+ const styles = StyleSheet.create({
44
+ error: {
45
+ backgroundColor: 'firebrick',
46
+ color: 'white',
47
+ },
48
+ });
@@ -0,0 +1,7 @@
1
+ interface Process {
2
+ env: {
3
+ [key: string]: string | undefined;
4
+ };
5
+ }
6
+
7
+ declare const process: Process;