-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #46843 Add some simple tests for ReactViewGroup clipping logic Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D63903975 fbshipit-source-id: 8ce683a4aeba2f3916a26d7b4e93b4a30227c6d5
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...act-native/ReactAndroid/src/test/java/com/facebook/react/views/view/ReactViewGroupTest.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,79 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.views.view | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.Robolectric | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class ReactViewGroupTest { | ||
|
||
private lateinit var context: Context | ||
|
||
@Before | ||
fun setUp() { | ||
ReactNativeFeatureFlagsForTests.setUp() | ||
context = Robolectric.buildActivity(Activity::class.java).create().get() | ||
} | ||
|
||
@Test | ||
fun `View clipping - ensure allChildren properly resizes when adding views in sequence`() { | ||
val rvg = ReactViewGroup(context) | ||
rvg.left = 0 | ||
rvg.right = 100 | ||
rvg.top = 0 | ||
rvg.bottom = 100 | ||
FrameLayout(context).addView(rvg) | ||
rvg.removeClippedSubviews = true | ||
for (i in 0..20) { | ||
rvg.addViewWithSubviewClippingEnabled(TestView(context, i * 10), i) | ||
} | ||
rvg.updateClippingRect() | ||
assertThat(rvg.childCount).isEqualTo(10) | ||
} | ||
|
||
@Test | ||
fun `View clipping - ensure allChildren properly resizes when adding views out of sequence`() { | ||
val rvg = ReactViewGroup(context) | ||
rvg.left = 0 | ||
rvg.right = 100 | ||
rvg.top = 0 | ||
rvg.bottom = 100 | ||
FrameLayout(context).addView(rvg) | ||
rvg.removeClippedSubviews = true | ||
for (i in 0..10) { | ||
rvg.addViewWithSubviewClippingEnabled(TestView(context, i * 10), i) | ||
} | ||
repeat(10) { rvg.addViewWithSubviewClippingEnabled(TestView(context, 90), 10) } | ||
rvg.updateClippingRect() | ||
assertThat(rvg.childCount).isEqualTo(20) | ||
} | ||
} | ||
|
||
class TestView(context: Context, yPos: Int) : View(context) { | ||
init { | ||
left = 0 | ||
right = 100 | ||
top = yPos | ||
bottom = top + 10 | ||
} | ||
} | ||
|
||
class TestParent(context: Context) : ViewGroup(context) { | ||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) = Unit | ||
} |