-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix showing Modal from TopBar components in RN 62 (#6199)
When showing React Native's Modal from a TopBar component - RNN mistakingly considered Modals as yellow boxes and removed them. Apparently this error surfaced in RN62
- Loading branch information
Showing
17 changed files
with
92 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...id/app/src/main/java/com/reactnativenavigation/viewcontrollers/NoOpYellowBoxDelegate.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...roid/app/src/main/java/com/reactnativenavigation/viewcontrollers/NoOpYellowBoxDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.reactnativenavigation.viewcontrollers | ||
|
||
import android.content.Context | ||
import android.view.View | ||
|
||
class NoOpYellowBoxDelegate(context: Context) : YellowBoxDelegate(context) { | ||
override fun onChildViewAdded(parent: View, child: View?) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
...ndroid/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.reactnativenavigation.viewcontrollers | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.RestrictTo | ||
import androidx.core.view.doOnPreDraw | ||
import androidx.core.view.forEachIndexed | ||
import androidx.core.view.get | ||
import com.reactnativenavigation.utils.isDebug | ||
import java.util.* | ||
|
||
open class YellowBoxDelegate(private val context: Context, private val yellowBoxHelper: YellowBoxHelper = YellowBoxHelper()) { | ||
constructor(context: Context) : this(context, YellowBoxHelper()) | ||
|
||
@get:RestrictTo(RestrictTo.Scope.TESTS) | ||
var parent: ViewGroup? = null | ||
private set | ||
@get:RestrictTo(RestrictTo.Scope.TESTS) | ||
val yellowBoxes: List<View> | ||
get() = yellowBoxViews | ||
|
||
private var isDestroyed = false | ||
private val yellowBoxViews = ArrayList<View>() | ||
|
||
open fun onChildViewAdded(parent: View, child: View?) { | ||
if (!context.isDebug()) return | ||
child?.doOnPreDraw { if (yellowBoxHelper.isYellowBox(parent, child)) onYellowBoxAdded(parent) } | ||
} | ||
|
||
fun onYellowBoxAdded(parent: View) { | ||
if (isDestroyed) return | ||
this.parent = parent as ViewGroup | ||
for (i in 1 until parent.childCount) { | ||
yellowBoxViews.add(parent[i]) | ||
parent.removeView(parent[i]) | ||
parent.addView(View(context), i) | ||
} | ||
} | ||
|
||
fun destroy() { | ||
isDestroyed = true | ||
if (yellowBoxViews.isNotEmpty()) yellowBoxViews.forEach { parent?.addView(it) } | ||
} | ||
} |
11 changes: 7 additions & 4 deletions
11
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
package com.reactnativenavigation.viewcontrollers; | ||
|
||
import androidx.annotation.NonNull; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.facebook.react.views.view.ReactViewBackgroundDrawable; | ||
import com.reactnativenavigation.utils.ViewUtils; | ||
|
||
class YellowBoxHelper { | ||
import androidx.annotation.NonNull; | ||
|
||
import static com.reactnativenavigation.utils.ViewUtils.findChildrenByClassRecursive; | ||
|
||
public class YellowBoxHelper { | ||
private final static int YELLOW_BOX_COLOR = -218449360; | ||
|
||
boolean isYellowBox(View parent, View child) { | ||
return parent instanceof ViewGroup && | ||
child instanceof ViewGroup && | ||
((ViewGroup) parent).getChildCount() > 1 && | ||
!ViewUtils.findChildrenByClassRecursive((ViewGroup) child, View.class, YellowBackgroundMather((ViewGroup) child)).isEmpty(); | ||
!findChildrenByClassRecursive((ViewGroup) child, View.class, YellowBackgroundMather()).isEmpty(); | ||
} | ||
|
||
@NonNull | ||
private static ViewUtils.Matcher<View> YellowBackgroundMather(ViewGroup vg) { | ||
private static ViewUtils.Matcher<View> YellowBackgroundMather() { | ||
return child1 -> child1.getBackground() instanceof ReactViewBackgroundDrawable && ((ReactViewBackgroundDrawable) child1.getBackground()).getColor() == YELLOW_BOX_COLOR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters