Skip to content

Commit 0afc26c

Browse files
committed
fix: prevent multiple renders during layout calculation on new arch
1 parent a141909 commit 0afc26c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/hooks/useLayout.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FABRIC_ENABLED, MAX_VALUE } from '../constants';
1010
*/
1111
export const useLayout = ({ enterFrom }: Notification) => {
1212
const [isLayoutReady, setLayoutReady] = useState(false);
13+
const isLayoutReadyRef = useRef(false);
1314
const ref = useRef<View>(null);
1415
// store current direction to handle the case when component dimensions changes (trigger onLayout)
1516
// while active direction != enterFrom (e.g. when exitTo is different than enterFrom, and notification started hiding animation).
@@ -66,7 +67,13 @@ export const useLayout = ({ enterFrom }: Notification) => {
6667
componentWidth.setValue(width);
6768

6869
updateHiddenValueByDirection(currentDirection.current);
69-
setLayoutReady(true);
70+
71+
// use ref to store the "isLayoutReady" value because calling setLayoutReady(true) more than once
72+
// in the new architecture triggers render more than once.
73+
if (!isLayoutReadyRef.current) {
74+
setLayoutReady(true);
75+
isLayoutReadyRef.current = true;
76+
}
7077
},
7178
[componentHeight, componentWidth, updateHiddenValueByDirection]
7279
);

0 commit comments

Comments
 (0)