react-native-morph-card 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -225,23 +225,18 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
225
225
  }
226
226
 
227
227
  /**
228
- * Walk the view tree and hide any screen container that isn't the source screen.
229
- * This catches modal screens added to separate ScreenStacks.
228
+ * Walk the view tree and hide any screen container that isn't already known.
229
+ * This catches modal screens added to separate ScreenStacks (e.g. transparentModal).
230
230
  */
231
- private fun hideNewScreenContainers(root: ViewGroup, sourceScreen: View?) {
231
+ private fun hideNewScreenContainers(root: ViewGroup, knownScreens: Set<View>) {
232
232
  fun walk(group: ViewGroup) {
233
233
  val name = group.javaClass.name
234
234
  if (name.contains("ScreenStack") || name.contains("ScreenContainer")) {
235
235
  for (i in 0 until group.childCount) {
236
236
  val child = group.getChildAt(i)
237
- if (child !== sourceScreen && child.visibility == View.VISIBLE) {
238
- // Check if this is a screen container we haven't seen before
239
- val childScreen = child
240
- val isSourceAncestor = isAncestorOf(childScreen, sourceScreen)
241
- if (!isSourceAncestor) {
242
- childScreen.visibility = View.INVISIBLE
243
- Log.d(TAG, "preDraw: hid screen container ${childScreen.javaClass.simpleName}")
244
- }
237
+ if (!knownScreens.contains(child) && child.visibility == View.VISIBLE) {
238
+ child.visibility = View.INVISIBLE
239
+ Log.d(TAG, "preDraw: hid new screen ${child.javaClass.simpleName} in ${group.javaClass.simpleName}")
245
240
  }
246
241
  }
247
242
  }
@@ -253,14 +248,25 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
253
248
  walk(root)
254
249
  }
255
250
 
256
- private fun isAncestorOf(potentialAncestor: View, target: View?): Boolean {
257
- if (target == null) return false
258
- var current: View? = target
259
- while (current != null) {
260
- if (current === potentialAncestor) return true
261
- current = if (current.parent is View) current.parent as View else null
251
+ /**
252
+ * Collect all current children of ScreenStack/ScreenContainer views.
253
+ */
254
+ private fun collectExistingScreens(root: ViewGroup): Set<View> {
255
+ val screens = mutableSetOf<View>()
256
+ fun walk(group: ViewGroup) {
257
+ val name = group.javaClass.name
258
+ if (name.contains("ScreenStack") || name.contains("ScreenContainer")) {
259
+ for (i in 0 until group.childCount) {
260
+ screens.add(group.getChildAt(i))
261
+ }
262
+ }
263
+ for (i in 0 until group.childCount) {
264
+ val child = group.getChildAt(i)
265
+ if (child is ViewGroup) walk(child)
266
+ }
262
267
  }
263
- return false
268
+ walk(root)
269
+ return screens
264
270
  }
265
271
 
266
272
  private fun removeHierarchyListener() {
@@ -344,9 +350,10 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
344
350
  // Also install a pre-draw listener on the DecorView to catch modal screens
345
351
  // that are added to a different ScreenStack (e.g. transparentModal).
346
352
  // This fires before every frame draw, so we can hide screens before they render.
347
- val savedSourceScreen = sourceScreen
353
+ val knownScreens = collectExistingScreens(decorView)
354
+ Log.d(TAG, "prepareExpand: tracking ${knownScreens.size} existing screens")
348
355
  val pdListener = ViewTreeObserver.OnPreDrawListener {
349
- hideNewScreenContainers(decorView, savedSourceScreen)
356
+ hideNewScreenContainers(decorView, knownScreens)
350
357
  true
351
358
  }
352
359
  decorView.viewTreeObserver.addOnPreDrawListener(pdListener)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-morph-card",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Native card-to-modal morph transition for React Native. iOS App Store-style expand animation.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",