diff --git a/example/app/issues/72/index.tsx b/example/app/issues/72/index.tsx new file mode 100644 index 0000000..aa34b7a --- /dev/null +++ b/example/app/issues/72/index.tsx @@ -0,0 +1,183 @@ +import { useState } from 'react'; +import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { Stack } from 'expo-router'; +import { EaseView } from 'react-native-ease'; + +// Issue #72 — iOS: a recycled EaseView loses overflow: 'hidden' and +// borderRadius. +// https://github.com/appandflow/react-native-ease/issues/72 +// +// prepareForRecycle reset masksToBounds and cornerRadius on the layer, but +// RCTViewComponentView keeps _props across recycling and only applies a style +// value again when it changes. Remounted with the same style, the view stays +// unclipped with square corners. +// +// Steps to reproduce: +// A. Press Unmount A, then Mount A again (the pill reuses the recycled view). +// Expected: the same rounded red pill. Without the fix: the whole 300x300 +// red square shows, with square corners. +// B. Press Unmount B, then Mount B again. Odd mounts use transformOrigin +// top-left and animate only opacity; even mounts use the default origin and +// scale to 0.6. Expected: the scaled square sits centred in the outline. If +// anchorPoint is not reset on recycle, it scales from the top-left instead. + +export default function RecycledViewScreen() { + const [clipShown, setClipShown] = useState(true); + const [clipMounts, setClipMounts] = useState(1); + const [anchorShown, setAnchorShown] = useState(true); + const [anchorMounts, setAnchorMounts] = useState(1); + const topLeftOrigin = anchorMounts % 2 === 1; + + return ( + + + + Unmount and mount each case again. A must stay a rounded pill. B must + stay centred in its outline on even mounts. + + + github.com/appandflow/react-native-ease/issues/72 + + + A — clipping, mount #{clipMounts} + + {clipShown && ( + + + + )} + + { + if (!clipShown) setClipMounts((n) => n + 1); + setClipShown((s) => !s); + }} + > + + {clipShown ? 'Unmount A' : 'Mount A again'} + + + + + B — anchor, mount #{anchorMounts} ( + {topLeftOrigin ? 'origin top-left, opacity' : 'default origin, scale'}) + + + + + {anchorShown && + (topLeftOrigin ? ( + + ) : ( + + ))} + + + { + if (!anchorShown) setAnchorMounts((n) => n + 1); + setAnchorShown((s) => !s); + }} + > + + {anchorShown ? 'Unmount B' : 'Mount B again'} + + + + ); +} + +const styles = StyleSheet.create({ + root: { + flex: 1, + padding: 20, + backgroundColor: '#1a1a2e', + }, + body: { + color: '#a0a0c0', + fontSize: 14, + lineHeight: 20, + marginBottom: 8, + }, + link: { + color: '#6666aa', + fontSize: 12, + marginBottom: 20, + }, + cardTitle: { + fontSize: 15, + fontWeight: '600', + color: '#e0e0ff', + marginBottom: 8, + }, + stage: { + height: 130, + alignItems: 'center', + justifyContent: 'center', + marginBottom: 12, + }, + pill: { + width: 160, + height: 64, + borderRadius: 32, + overflow: 'hidden', + backgroundColor: '#4a90d9', + }, + oversized: { + width: 300, + height: 300, + backgroundColor: '#e05555', + }, + outline: { + width: 120, + height: 120, + borderWidth: 1, + borderStyle: 'dashed', + borderColor: '#6666aa', + alignItems: 'center', + justifyContent: 'center', + }, + expected: { + position: 'absolute', + width: 72, + height: 72, + borderWidth: 1, + borderColor: '#5fd38d', + }, + square: { + width: 120, + height: 120, + backgroundColor: '#4a90d9', + }, + squareFaint: { + backgroundColor: '#4a90d966', + }, + button: { + alignSelf: 'center', + paddingHorizontal: 20, + paddingVertical: 12, + borderRadius: 10, + backgroundColor: '#16213e', + marginBottom: 24, + }, + buttonText: { + color: '#e0e0ff', + fontSize: 15, + fontWeight: '600', + }, +}); diff --git a/example/src/demos/index.ts b/example/src/demos/index.ts index 6244322..e5dab13 100644 --- a/example/src/demos/index.ts +++ b/example/src/demos/index.ts @@ -165,6 +165,11 @@ export const demos: Record = { title: 'Issue #66 — Background loops', section: 'Issues', }, + 'issue-72': { + route: '/issues/72', + title: 'Issue #72 — Recycled clipping', + section: 'Issues', + }, 'issue-loop-cancel': { route: '/issues/loop-cancel', title: 'Audit — Cancelled loop resurrects', diff --git a/ios/EaseView.mm b/ios/EaseView.mm index fa652de..7cdc5bc 100644 --- a/ios/EaseView.mm +++ b/ios/EaseView.mm @@ -1664,18 +1664,42 @@ - (void)prepareForRecycle { _transformOriginX = 0.5; _transformOriginY = 0.5; _transformPerspective = 1280.0; + // Reset only what this view animated: RCTViewComponentView keeps _props + // across recycling and won't re-apply an unchanged style value (overflow, + // borderRadius, ...). anchorPoint is ours (transformOrigin), so always reset. + const auto &oldProps = *std::static_pointer_cast(_props); + const int mask = oldProps.animatedProperties; self.layer.anchorPoint = CGPointMake(0.5, 0.5); - self.layer.opacity = 1.0; - self.layer.transform = CATransform3DIdentity; - self.layer.cornerRadius = 0; - self.layer.masksToBounds = NO; - self.layer.backgroundColor = nil; - self.layer.borderWidth = 0; - self.layer.borderColor = nil; - self.layer.shadowOpacity = 0; - self.layer.shadowRadius = 0; - self.layer.shadowColor = nil; - self.layer.shadowOffset = CGSizeZero; + if (mask & kMaskAnyTransform) { + self.layer.transform = CATransform3DIdentity; + } + if (mask & kMaskOpacity) { + self.layer.opacity = 1.0; + } + if (mask & kMaskBorderRadius) { + self.layer.cornerRadius = 0; + } + if (mask & kMaskBackgroundColor) { + self.layer.backgroundColor = nil; + } + if (mask & kMaskBorderWidth) { + self.layer.borderWidth = 0; + } + if (mask & kMaskBorderColor) { + self.layer.borderColor = nil; + } + if (mask & kMaskShadowOpacity) { + self.layer.shadowOpacity = 0; + } + if (mask & kMaskShadowRadius) { + self.layer.shadowRadius = 0; + } + if (mask & kMaskShadowColor) { + self.layer.shadowColor = nil; + } + if (mask & kMaskShadowOffset) { + self.layer.shadowOffset = CGSizeZero; + } } @end