Skip to content

Commit 72dd4ce

Browse files
committed
implement realistic hiding elements
1 parent 4d78825 commit 72dd4ce

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/render.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import type { StyleProp } from 'react-native';
23
import {
34
createRoot,
45
type HostElement,
@@ -39,6 +40,10 @@ export async function render<T>(element: React.ReactElement<T>, options: RenderO
3940
const rendererOptions: RootOptions = {
4041
textComponentTypes: HOST_TEXT_NAMES,
4142
publicTextComponentTypes: ['Text'],
43+
transformHiddenInstanceProps: ({ props }) => ({
44+
...props,
45+
style: withHiddenStyle(props.style as StyleProp<StyleLike>),
46+
}),
4247
};
4348

4449
const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);
@@ -117,3 +122,13 @@ function makeDebug(renderer: Root): DebugFunction {
117122
}
118123
return debugImpl;
119124
}
125+
126+
type StyleLike = Record<string, unknown>;
127+
128+
function withHiddenStyle(style: StyleProp<StyleLike>): StyleProp<StyleLike> {
129+
if (style == null) {
130+
return null;
131+
}
132+
133+
return [style, { display: 'none' }];
134+
}

0 commit comments

Comments
 (0)