Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f06a493
Fix typo in README (#1495)
Andarius Jul 5, 2021
6845554
Bump prismjs from 1.23.0 to 1.24.0 in /docs (#1491)
dependabot[bot] Jul 5, 2021
b172a79
Fix compatibility with React 18 (#1500)
janicduplessis Jul 7, 2021
777fab8
Add duration to long press event (#1505)
j-piasecki Jul 16, 2021
9f18535
Revert "Don't fail PanGestureHandler on tap (#603)" (#1508)
j-piasecki Jul 19, 2021
1bbfe2c
Bump dependencies (#1520)
jgonet Jul 28, 2021
79e4c34
Fix iteration over argument mapping on web (#1504)
machouz Aug 4, 2021
c436311
Import UIManager directly from react-native (#1528)
acoates-ms Aug 4, 2021
d5fc498
Bump tar from 6.0.5 to 6.1.4 in /docs (#1536)
dependabot[bot] Aug 4, 2021
e675e13
Add kotlin plugin to build.gradle (#1514)
jgonet Jul 28, 2021
fb2bcbc
Convert Package to Kotlin (#1517)
jgonet Jul 29, 2021
a5fdde3
Convert root views to Kotlin (#1516)
jgonet Jul 29, 2021
9ff6cd5
Convert Registry to Kotlin (#1519)
jgonet Jul 29, 2021
4846830
Convert ButtonViewManager to Kotlin (#1515)
jgonet Jul 29, 2021
374cc7f
Convert base GestureHandler class to Kotlin (#1518)
jgonet Jul 29, 2021
aa240f5
Convert InteractionManager & Controller to Kotlin (#1522)
jgonet Jul 30, 2021
ad4996b
Convert FlingGH to Kotlin (#1523)
jgonet Jul 30, 2021
4eef8a4
Convert helpers to Kotlin (#1521)
jgonet Jul 30, 2021
a9416dd
Convert LongPress to Kotlin (#1524)
jgonet Jul 30, 2021
7195f81
Convert PanGH to Kotlin (#1526)
jgonet Jul 30, 2021
380a73d
Rewrite NativeView to Kotlin (#1525)
jgonet Jul 30, 2021
7cfba39
Convert PinchGH to Kotlin (#1527)
jgonet Aug 2, 2021
6193d69
Convert TapGH to Kotlin (#1530)
jgonet Aug 2, 2021
ff194fc
Convert RotationGH to Kotlin (#1529)
jgonet Aug 2, 2021
ca3e07f
Convert GestureHandlerRegistry to Kotlin (#1535)
jgonet Aug 4, 2021
236ecae
Convert events to Kotlin (#1534)
jgonet Aug 4, 2021
0d50f7f
Rewrite Orchestrator to Kotlin (#1533)
jgonet Aug 4, 2021
d18525a
Convert enums & interfaces to Kotlin (#1537)
jgonet Aug 4, 2021
9c7664b
Rename fields in GestureHandler (#1539)
jgonet Aug 4, 2021
a33f415
Convert Module to Kotlin (#1538)
jgonet Aug 5, 2021
e55a33d
Bump tar from 4.4.8 to 4.4.15 in /ci/e2e (#1540)
dependabot[bot] Aug 5, 2021
d2e3fd6
Bump tar from 6.0.5 to 6.1.6 in /examples/Example (#1541)
dependabot[bot] Aug 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ jsconfig.json
dist/

# generated by bob
lib/
/lib/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Check out our dedicated documentation page for info about this library, API refe

## Examples

If you want to play with the API but don't feel like trying it on a real app, you can run the example project. Clone the repo, go to the `Example/` folder and run:
If you want to play with the API but don't feel like trying it on a real app, you can run the example project. Clone the repo, go to the `examples/Example/` folder and run:

```bash
yarn install
Expand Down
9 changes: 8 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

repositories {
mavenCentral()
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 28)

Expand All @@ -14,7 +19,7 @@ android {
versionName "1.0"
}

// Include "lib/" as sources, unfortunetely react-native link can't handle
// Include "lib/" as sources, unfortunately react-native link can't handle
// setting up alternative gradle modules. We still have "lib" defined as a
// standalone gradle module just to be used in AndroidNativeExample
sourceSets {
Expand All @@ -26,4 +31,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.20"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.swmansion.gesturehandler

abstract class BaseGestureHandlerInteractionController : GestureHandlerInteractionController {
override fun shouldWaitForHandlerFailure(
handler: GestureHandler<*>,
otherHandler: GestureHandler<*>,
) = false

override fun shouldRequireHandlerToWaitForFailure(
handler: GestureHandler<*>,
otherHandler: GestureHandler<*>,
) = false

override fun shouldRecognizeSimultaneously(
handler: GestureHandler<*>,
otherHandler: GestureHandler<*>,
) = false
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.swmansion.gesturehandler

import android.os.Handler
import android.view.MotionEvent

class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
var numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED
var direction = DEFAULT_DIRECTION

private val maxDurationMs = DEFAULT_MAX_DURATION_MS
private val minAcceptableDelta = DEFAULT_MIN_ACCEPTABLE_DELTA
private var startX = 0f
private var startY = 0f
private var handler: Handler? = null
private var maxNumberOfPointersSimultaneously = 0
private val failDelayed = Runnable { fail() }

override fun resetConfig() {
super.resetConfig()
numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED
direction = DEFAULT_DIRECTION
}

private fun startFling(event: MotionEvent) {
startX = event.rawX
startY = event.rawY
begin()
maxNumberOfPointersSimultaneously = 1
if (handler == null) {
handler = Handler() // lazy delegate?
} else {
handler!!.removeCallbacksAndMessages(null)
}
handler!!.postDelayed(failDelayed, maxDurationMs)
}

private fun tryEndFling(event: MotionEvent) = if (
maxNumberOfPointersSimultaneously == numberOfPointersRequired &&
(direction and DIRECTION_RIGHT != 0 &&
event.rawX - startX > minAcceptableDelta ||
direction and DIRECTION_LEFT != 0 &&
startX - event.rawX > minAcceptableDelta ||
direction and DIRECTION_UP != 0 &&
startY - event.rawY > minAcceptableDelta ||
direction and DIRECTION_DOWN != 0 &&
event.rawY - startY > minAcceptableDelta)) {
handler!!.removeCallbacksAndMessages(null)
activate()
end()
true
} else {
false
}


private fun endFling(event: MotionEvent) {
if (!tryEndFling(event)) {
fail()
}
}

override fun onHandle(event: MotionEvent) {
val state = state
if (state == STATE_UNDETERMINED) {
startFling(event)
}
if (state == STATE_BEGAN) {
tryEndFling(event)
if (event.pointerCount > maxNumberOfPointersSimultaneously) {
maxNumberOfPointersSimultaneously = event.pointerCount
}
val action = event.actionMasked
if (action == MotionEvent.ACTION_UP) {
endFling(event)
}
}
}

override fun onCancel() {
handler?.removeCallbacksAndMessages(null)
}

override fun onReset() {
handler?.removeCallbacksAndMessages(null)
}

companion object {
private const val DEFAULT_MAX_DURATION_MS: Long = 800
private const val DEFAULT_MIN_ACCEPTABLE_DELTA: Long = 160
private const val DEFAULT_DIRECTION = DIRECTION_RIGHT
private const val DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1
}
}
Loading