-
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.
When the Overlay was displayed with `statusBar.drawBehind: false`, the StatusBar height wasn't accounted for when calculating if touch events were inside the view's bounds. To begin with, StatusBar height had to be accounted for because we used `MotionEvent.rawY` coordinates instead of `MotionEvent.y` coordinate which already take into account the view's position within the hierarchy, which compensates for StatusBar height. fixes #5976
- Loading branch information
Showing
8 changed files
with
108 additions
and
60 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
13 changes: 13 additions & 0 deletions
13
lib/android/app/src/main/java/com/reactnativenavigation/utils/MotionEvent.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,13 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
import android.graphics.Rect | ||
import android.view.MotionEvent | ||
import android.view.View | ||
|
||
val hitRect = Rect() | ||
|
||
fun MotionEvent.coordinatesInsideView(view: View?): Boolean { | ||
view ?: return false | ||
view.getHitRect(hitRect) | ||
return hitRect.contains(x.toInt(), y.toInt()) | ||
} |
49 changes: 0 additions & 49 deletions
49
...android/app/src/main/java/com/reactnativenavigation/views/touch/OverlayTouchDelegate.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
lib/android/app/src/main/java/com/reactnativenavigation/views/touch/OverlayTouchDelegate.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,26 @@ | ||
package com.reactnativenavigation.views.touch | ||
|
||
import android.view.MotionEvent | ||
import androidx.annotation.VisibleForTesting | ||
import com.reactnativenavigation.options.params.Bool | ||
import com.reactnativenavigation.options.params.NullBool | ||
import com.reactnativenavigation.react.ReactView | ||
import com.reactnativenavigation.utils.coordinatesInsideView | ||
import com.reactnativenavigation.views.component.ComponentLayout | ||
|
||
open class OverlayTouchDelegate(private val component: ComponentLayout, private val reactView: ReactView) { | ||
var interceptTouchOutside: Bool = NullBool() | ||
|
||
fun onInterceptTouchEvent(event: MotionEvent): Boolean { | ||
return when (interceptTouchOutside.hasValue() && event.actionMasked == MotionEvent.ACTION_DOWN) { | ||
true -> handleDown(event) | ||
false -> component.superOnInterceptTouchEvent(event) | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
open fun handleDown(event: MotionEvent) = when (event.coordinatesInsideView(reactView.getChildAt(0))) { | ||
true -> component.superOnInterceptTouchEvent(event) | ||
false -> interceptTouchOutside.isFalse | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
lib/android/app/src/test/java/com/reactnativenavigation/utils/MotionEventTest.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,49 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
import android.app.Activity | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.view.View.MeasureSpec | ||
import android.widget.FrameLayout | ||
import androidx.core.view.marginTop | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import com.reactnativenavigation.BaseTest | ||
import org.assertj.core.api.Java6Assertions.assertThat | ||
import org.junit.Test | ||
|
||
class MotionEventTest : BaseTest() { | ||
private lateinit var uut: MotionEvent | ||
private lateinit var activity: Activity | ||
private lateinit var parent: FrameLayout | ||
private val x = 173f | ||
private val y = 249f | ||
|
||
override fun beforeEach() { | ||
uut = MotionEvent.obtain(0L, 0, 0, x, y, 0) | ||
activity = newActivity() | ||
parent = FrameLayout(activity) | ||
activity.setContentView(parent) | ||
} | ||
|
||
@Test | ||
fun coordinatesInsideView() { | ||
val v: View = mock() | ||
assertThat(uut.coordinatesInsideView(v)).isFalse() | ||
} | ||
|
||
@Test | ||
fun coordinatesInsideView_inside() { | ||
val view = View(activity) | ||
parent.addView(view, 200, 300) | ||
assertThat(uut.coordinatesInsideView(view)).isTrue() | ||
} | ||
|
||
@Test | ||
fun coordinatesInsideView_outside() { | ||
val view = View(activity) | ||
parent.addView(view, 200, 300) | ||
view.top = (y + 1).toInt() | ||
assertThat(uut.coordinatesInsideView(view)).isFalse() | ||
} | ||
} |
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