Skip to content

Commit

Permalink
make tap on gesture surface ignore tiny movments when tapping
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 8, 2024
1 parent 0991e82 commit dc88aca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ class NewPlayerViewModelImpl @Inject constructor(
if (!uiState.value.uiMode.fullscreen && newUiModeState.fullscreen && embeddedUiConfig != null) {
this.embeddedUiConfig = embeddedUiConfig
}
newUiModeState.fullscreen

if ((newUiModeState == UIModeState.EMBEDDED_VIDEO_CONTROLLER_UI ||
newUiModeState == UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ internal fun EmbeddedGestureUI(
}
}

val handleUp = {
downwardMovementMode = false
sumOfMovement = 0f
}

val defaultOnRegularTap = {
if (uiState.uiMode.videoControllerUiVisible) {
viewModel.changeUiMode(uiState.uiMode.getUiHiddenState(), null)
Expand All @@ -102,6 +97,11 @@ internal fun EmbeddedGestureUI(
}
}

val handleUp = {
downwardMovementMode = false
sumOfMovement = 0f
}

Row(modifier = modifier) {
GestureSurface(
modifier = Modifier.weight(1f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -54,14 +56,15 @@ internal fun GestureSurface(
onMovement: (TouchedPosition) -> Unit = {},
content: @Composable () -> Unit = {}
) {
var moveOccured by remember {
mutableStateOf(false)
}

var lastTouchedPosition by remember {
mutableStateOf(TouchedPosition(0f, 0f))
}

var yMovementSum by remember {
mutableFloatStateOf(0f)
}

var lastFingerUpTime by remember {
mutableStateOf(System.currentTimeMillis())
}
Expand All @@ -73,12 +76,13 @@ internal fun GestureSurface(

val defaultActionDown = { event: MotionEvent ->
lastTouchedPosition = TouchedPosition(event.x, event.y)
moveOccured = false
yMovementSum = 0f

true
}

var multitapAmount:Int by remember {
mutableStateOf(0)
mutableIntStateOf(0)
}

var cancelMultitapJob: Job? by remember {
Expand All @@ -87,7 +91,8 @@ internal fun GestureSurface(

val defaultActionUp = { onMultiTap: (Int) -> Unit, onRegularTap: () -> Unit ->
onUp()
if (!moveOccured) {

if (yMovementSum < 10) {
val currentTime = System.currentTimeMillis()
val timeSinceLastTouch = currentTime - lastFingerUpTime
if (timeSinceLastTouch <= MULTITAB_MODE_DELAY) {
Expand All @@ -109,7 +114,7 @@ internal fun GestureSurface(

lastFingerUpTime = currentTime
}
moveOccured = false
yMovementSum = 0f
true
}

Expand All @@ -118,7 +123,8 @@ internal fun GestureSurface(
val movement = currentTouchedPosition - lastTouchedPosition

lastTouchedPosition = currentTouchedPosition
moveOccured = true

yMovementSum += abs(movement.y)

// filter out left and right movements as these are not important for the app
if(abs(movement.x) <= abs(movement.y)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

val newPlayerViewModel: NewPlayerViewModel by viewModels<NewPlayerViewModelImpl>()
private val newPlayerViewModel: NewPlayerViewModel by viewModels<NewPlayerViewModelImpl>()

private var currentOrientation = -1
private var reconfigurationPending = false
Expand Down

0 comments on commit dc88aca

Please sign in to comment.