1*641d0767SEvan Baconimport React from 'react';
2*641d0767SEvan Baconimport { Platform, StyleSheet, Text } from 'react-native';
3*641d0767SEvan Baconfunction useChildren(inputChildren) {
4*641d0767SEvan Bacon    return React.useMemo(() => {
5*641d0767SEvan Bacon        const children = [];
6*641d0767SEvan Bacon        React.Children.forEach(inputChildren, (child) => {
7*641d0767SEvan Bacon            if (child == null || typeof child === 'boolean') {
8*641d0767SEvan Bacon            }
9*641d0767SEvan Bacon            else if (typeof child === 'string' || typeof child === 'number') {
10*641d0767SEvan Bacon                // Wrap text in a Text component.
11*641d0767SEvan Bacon                let message = `Invalid raw text as a child of View: "${child}"${child === '' ? ` [empty string]` : ''}.`;
12*641d0767SEvan Bacon                message += ' Wrap the text contents with a Text element or remove it.';
13*641d0767SEvan Bacon                console.warn(message);
14*641d0767SEvan Bacon                children.push(React.createElement(Text, { style: [StyleSheet.absoluteFill, styles.error] },
15*641d0767SEvan Bacon                    "Unwrapped text: \"",
16*641d0767SEvan Bacon                    React.createElement(Text, { style: { fontWeight: 'bold' } }, child),
17*641d0767SEvan Bacon                    "\""));
18*641d0767SEvan Bacon            }
19*641d0767SEvan Bacon            else if ('type' in child && typeof child?.type === 'string' && Platform.OS !== 'web') {
20*641d0767SEvan Bacon                // Disallow untransformed react-dom elements on native.
21*641d0767SEvan Bacon                throw new Error(`Using unsupported React DOM element: <${child.type} />`);
22*641d0767SEvan Bacon            }
23*641d0767SEvan Bacon            else {
24*641d0767SEvan Bacon                children.push(child);
25*641d0767SEvan Bacon            }
26*641d0767SEvan Bacon        });
27*641d0767SEvan Bacon        return children;
28*641d0767SEvan Bacon    }, [inputChildren]);
29*641d0767SEvan Bacon}
30*641d0767SEvan Bacon/** Extend a view with a `children` filter that asserts more helpful warnings/errors. */
31*641d0767SEvan Baconexport function createDevView(View) {
32*641d0767SEvan Bacon    return React.forwardRef(({ children, ...props }, forwardedRef) => {
33*641d0767SEvan Bacon        return React.createElement(View, { ref: forwardedRef, ...props, children: useChildren(children) });
34*641d0767SEvan Bacon    });
35*641d0767SEvan Bacon}
36*641d0767SEvan Baconconst styles = StyleSheet.create({
37*641d0767SEvan Bacon    error: {
38*641d0767SEvan Bacon        backgroundColor: 'firebrick',
39*641d0767SEvan Bacon        color: 'white',
40*641d0767SEvan Bacon    },
41*641d0767SEvan Bacon});
42*641d0767SEvan Bacon//# sourceMappingURL=createDevView.js.map