react-native-swipeable-actions 0.1.11 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/LICENSE +21 -0
- package/README.md +377 -207
- package/android/src/main/java/expo/modules/swipeable/SwipePhysics.kt +39 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeableModule.kt +24 -10
- package/android/src/main/java/expo/modules/swipeable/SwipeableView.kt +804 -420
- package/build/Swipeable.d.ts +3 -8
- package/build/Swipeable.d.ts.map +1 -1
- package/build/Swipeable.js +87 -33
- package/build/Swipeable.js.map +1 -1
- package/build/Swipeable.types.d.ts +59 -9
- package/build/Swipeable.types.d.ts.map +1 -1
- package/build/SwipeableActions.d.ts +1 -1
- package/build/SwipeableActions.d.ts.map +1 -1
- package/build/SwipeableActions.js +4 -2
- package/build/SwipeableActions.js.map +1 -1
- package/build/SwipeableView.d.ts +11 -2
- package/build/SwipeableView.d.ts.map +1 -1
- package/build/SwipeableView.js.map +1 -1
- package/build/constants.d.ts +0 -1
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +0 -1
- package/build/constants.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/nativeModuleUtils.d.ts +3 -1
- package/build/nativeModuleUtils.d.ts.map +1 -1
- package/build/nativeModuleUtils.js +20 -9
- package/build/nativeModuleUtils.js.map +1 -1
- package/build/resolveSwipeableActions.d.ts +18 -0
- package/build/resolveSwipeableActions.d.ts.map +1 -0
- package/build/resolveSwipeableActions.js +26 -0
- package/build/resolveSwipeableActions.js.map +1 -0
- package/docs/migration-v1.md +191 -0
- package/docs/support.md +90 -0
- package/ios/SwipeAnimationConfig.swift +32 -0
- package/ios/SwipePhysics.swift +418 -0
- package/ios/SwipeableModule.swift +34 -12
- package/ios/SwipeableView.swift +1061 -600
- package/jestSetup.js +17 -5
- package/package.json +11 -5
- package/src/Swipeable.tsx +147 -54
- package/src/Swipeable.types.ts +50 -9
- package/src/SwipeableActions.tsx +6 -3
- package/src/SwipeableView.tsx +10 -3
- package/src/constants.ts +0 -1
- package/src/index.ts +7 -0
- package/src/nativeModuleUtils.ts +19 -8
- package/src/resolveSwipeableActions.ts +37 -0
|
@@ -4,7 +4,46 @@ import kotlin.math.abs
|
|
|
4
4
|
import kotlin.math.min
|
|
5
5
|
import kotlin.math.sign
|
|
6
6
|
|
|
7
|
+
enum class SwipeSide(val value: String, val sign: Float) {
|
|
8
|
+
LEFT("left", 1f), RIGHT("right", -1f);
|
|
9
|
+
|
|
10
|
+
companion object {
|
|
11
|
+
fun fromValue(value: String?): SwipeSide? = values().firstOrNull { it.value == value }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
object SwipePhysics {
|
|
16
|
+
private fun enabled(width: Float): Boolean = width.isFinite() && width > 0f
|
|
17
|
+
|
|
18
|
+
fun defaultOpenSide(leftWidth: Float, rightWidth: Float): SwipeSide? {
|
|
19
|
+
return when {
|
|
20
|
+
enabled(rightWidth) -> SwipeSide.RIGHT
|
|
21
|
+
enabled(leftWidth) -> SwipeSide.LEFT
|
|
22
|
+
else -> null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Physical edge selection; an existing latch cannot change until the next gesture. */
|
|
27
|
+
fun selectSide(
|
|
28
|
+
translation: Float,
|
|
29
|
+
openSide: SwipeSide?,
|
|
30
|
+
latchedSide: SwipeSide?,
|
|
31
|
+
leftWidth: Float,
|
|
32
|
+
rightWidth: Float
|
|
33
|
+
): SwipeSide? {
|
|
34
|
+
val side = latchedSide ?: openSide ?: when {
|
|
35
|
+
translation > 0f -> SwipeSide.LEFT
|
|
36
|
+
translation < 0f -> SwipeSide.RIGHT
|
|
37
|
+
else -> return null
|
|
38
|
+
}
|
|
39
|
+
return side.takeIf { enabled(if (it == SwipeSide.LEFT) leftWidth else rightWidth) }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fun applyLatchedTranslation(startOffset: Float, translation: Float, friction: Float, width: Float, side: SwipeSide): Float {
|
|
43
|
+
val raw = startOffset + translation * friction
|
|
44
|
+
val clamped = if (side == SwipeSide.LEFT) maxOf(0f, raw) else minOf(0f, raw)
|
|
45
|
+
return applyRubberBand(clamped, width, side == SwipeSide.LEFT)
|
|
46
|
+
}
|
|
8
47
|
|
|
9
48
|
fun applyRubberBand(
|
|
10
49
|
translation: Float,
|
|
@@ -12,6 +12,10 @@ class SwipeableModule : Module() {
|
|
|
12
12
|
SwipeableView.openByKey(key)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
Function("openByKeyOnSide") { key: String, side: String? ->
|
|
16
|
+
SwipeableView.openByKeyOnSide(key, SwipeSide.fromValue(side))
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
Function("closeByKey") { key: String, animated: Boolean? ->
|
|
16
20
|
SwipeableView.closeByKey(key, animated ?: true)
|
|
17
21
|
}
|
|
@@ -28,13 +32,12 @@ class SwipeableModule : Module() {
|
|
|
28
32
|
SwipeableView.isOpenByKey(key)
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
Function("getOpenSideByKey") { key: String ->
|
|
36
|
+
SwipeableView.getOpenSideByKey(key)
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
View(SwipeableView::class) {
|
|
32
|
-
|
|
33
|
-
view.actionsWidth = width
|
|
34
|
-
}
|
|
35
|
-
Prop("actionsPosition") { view: SwipeableView, position: String ->
|
|
36
|
-
view.actionsPosition = position
|
|
37
|
-
}
|
|
40
|
+
|
|
38
41
|
Prop("friction") { view: SwipeableView, friction: Float ->
|
|
39
42
|
view.friction = friction.coerceIn(0f, 1f)
|
|
40
43
|
}
|
|
@@ -57,16 +60,27 @@ class SwipeableModule : Module() {
|
|
|
57
60
|
view.autoCloseTimeout = timeout
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
Prop("leftActionsWidth") { view: SwipeableView, width: Float ->
|
|
64
|
+
view.leftActionsWidth = width
|
|
65
|
+
}
|
|
66
|
+
Prop("rightActionsWidth") { view: SwipeableView, width: Float ->
|
|
67
|
+
view.rightActionsWidth = width
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
OnViewDidUpdateProps { view: SwipeableView ->
|
|
71
|
+
view.applyPendingConfiguration()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Events("onSwipeProgress", "onSwipeStart", "onSwipeStateChange", "onSwipeEnd", "onActionsNeeded", "onGestureCancelled")
|
|
61
75
|
|
|
62
76
|
AsyncFunction("close") { view: SwipeableView, animated: Boolean? ->
|
|
63
|
-
view.
|
|
77
|
+
view.postCommand { view.close(animated ?: true) }
|
|
64
78
|
}
|
|
65
79
|
AsyncFunction("open") { view: SwipeableView ->
|
|
66
|
-
view.
|
|
80
|
+
view.postCommand { view.open() }
|
|
67
81
|
}
|
|
68
82
|
AsyncFunction("cancel") { view: SwipeableView ->
|
|
69
|
-
view.
|
|
83
|
+
view.postCommand { view.cancelGesture() }
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
AsyncFunction("handleGestureStart") { view: SwipeableView ->
|