Skip to content

Commit

Permalink
Merge pull request #433 from jpudysz/feature/pressable
Browse files Browse the repository at this point in the history
feat: pressable nested variants
  • Loading branch information
jpudysz authored Dec 14, 2024
2 parents 23cc9e0 + 9876ad6 commit 65d30a2
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/native/Pressable.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,35 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
? unistyles
: [unistyles]

UnistylesShadowRegistry.selectVariants(variants)
// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.add(ref, styles)
UnistylesShadowRegistry.selectVariants(undefined)

storedRef.current = ref

return passForwardedRef(props, ref, forwardedRef)
}}
style={state => {
UnistylesShadowRegistry.selectVariants(variants)

const unistyles = typeof style === 'function'
? style(state)
: style
const styles = Array.isArray(unistyles)
? unistyles
: [unistyles]

if (storedRef.current) {
// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.remove(storedRef.current)
// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.add(storedRef.current, styles)
if (!storedRef.current) {
return unistyles
}

UnistylesShadowRegistry.selectVariants(undefined)
if (state.pressed) {
UnistylesShadowRegistry.selectVariants(variants)
}

// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.remove(storedRef.current)
// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.add(storedRef.current, styles)

return unistyles
}}
Expand Down

0 comments on commit 65d30a2

Please sign in to comment.