diff --git a/src/components/native/Pressable.native.tsx b/src/components/native/Pressable.native.tsx index cc395acd..239ac2a8 100644 --- a/src/components/native/Pressable.native.tsx +++ b/src/components/native/Pressable.native.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, useRef } from 'react' +import React, { forwardRef, useEffect, useRef } from 'react' import { Pressable as NativePressableReactNative } from 'react-native' import type { PressableProps as Props, View } from 'react-native' import { UnistylesShadowRegistry } from '../../specs' @@ -11,6 +11,15 @@ type PressableProps = Props & { export const Pressable = forwardRef(({ variants, style, ...props }, forwardedRef) => { const storedRef = useRef() + useEffect(() => { + return () => { + if (storedRef.current) { + // @ts-expect-error - this is hidden from TS + UnistylesShadowRegistry.remove(storedRef.current) + } + } + }, []) + return ( (({ variants, style, .. const unistyles = typeof style === 'function' ? style({ pressed: false }) : style - const styles = Array.isArray(unistyles) - ? unistyles - : [unistyles] // @ts-expect-error web types are not compatible with RN styles - UnistylesShadowRegistry.add(ref, styles) - storedRef.current = ref + UnistylesShadowRegistry.add(ref, unistyles) + + if (ref) { + storedRef.current = ref + } return passForwardedRef(props, ref, forwardedRef) }} @@ -32,18 +41,13 @@ export const Pressable = forwardRef(({ variants, style, .. const unistyles = typeof style === 'function' ? style(state) : style - const styles = Array.isArray(unistyles) - ? unistyles - : [unistyles] if (!storedRef.current) { return unistyles } - // @ts-expect-error hidden from TS - UnistylesShadowRegistry.remove(storedRef.current) // @ts-expect-error - this is hidden from TS - UnistylesShadowRegistry.add(storedRef.current, styles) + UnistylesShadowRegistry.add(storedRef.current, unistyles) return unistyles }} diff --git a/src/core/createUnistylesImageBackground.tsx b/src/core/createUnistylesImageBackground.tsx index 90379ad8..b12c86d4 100644 --- a/src/core/createUnistylesImageBackground.tsx +++ b/src/core/createUnistylesImageBackground.tsx @@ -42,12 +42,8 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground storedImageRef.current = ref } - const style = Array.isArray(props.imageStyle) - ? props.imageStyle - : [props.imageStyle] - // @ts-expect-error web types are not compatible with RN styles - UnistylesShadowRegistry.add(ref, style) + UnistylesShadowRegistry.add(ref, props.imageStyle) }} /> )