react-native-swipeable-actions 0.1.12 → 1.0.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/LICENSE +21 -0
  3. package/README.md +377 -207
  4. package/android/src/main/java/expo/modules/swipeable/SwipePhysics.kt +39 -0
  5. package/android/src/main/java/expo/modules/swipeable/SwipeableModule.kt +24 -10
  6. package/android/src/main/java/expo/modules/swipeable/SwipeableView.kt +804 -420
  7. package/build/Swipeable.d.ts +3 -8
  8. package/build/Swipeable.d.ts.map +1 -1
  9. package/build/Swipeable.js +87 -33
  10. package/build/Swipeable.js.map +1 -1
  11. package/build/Swipeable.types.d.ts +59 -9
  12. package/build/Swipeable.types.d.ts.map +1 -1
  13. package/build/SwipeableActions.d.ts +1 -1
  14. package/build/SwipeableActions.d.ts.map +1 -1
  15. package/build/SwipeableActions.js +4 -2
  16. package/build/SwipeableActions.js.map +1 -1
  17. package/build/SwipeableView.d.ts +11 -2
  18. package/build/SwipeableView.d.ts.map +1 -1
  19. package/build/SwipeableView.js.map +1 -1
  20. package/build/constants.d.ts +0 -1
  21. package/build/constants.d.ts.map +1 -1
  22. package/build/constants.js +0 -1
  23. package/build/constants.js.map +1 -1
  24. package/build/index.d.ts +1 -1
  25. package/build/index.d.ts.map +1 -1
  26. package/build/index.js.map +1 -1
  27. package/build/nativeModuleUtils.d.ts +3 -1
  28. package/build/nativeModuleUtils.d.ts.map +1 -1
  29. package/build/nativeModuleUtils.js +20 -9
  30. package/build/nativeModuleUtils.js.map +1 -1
  31. package/build/resolveSwipeableActions.d.ts +18 -0
  32. package/build/resolveSwipeableActions.d.ts.map +1 -0
  33. package/build/resolveSwipeableActions.js +26 -0
  34. package/build/resolveSwipeableActions.js.map +1 -0
  35. package/docs/migration-v1.md +191 -0
  36. package/docs/support.md +90 -0
  37. package/ios/SwipeAnimationConfig.swift +32 -0
  38. package/ios/SwipePhysics.swift +418 -0
  39. package/ios/SwipeableModule.swift +34 -12
  40. package/ios/SwipeableView.swift +1062 -613
  41. package/jestSetup.js +17 -5
  42. package/package.json +11 -5
  43. package/src/Swipeable.tsx +147 -54
  44. package/src/Swipeable.types.ts +50 -9
  45. package/src/SwipeableActions.tsx +6 -3
  46. package/src/SwipeableView.tsx +10 -3
  47. package/src/constants.ts +0 -1
  48. package/src/index.ts +7 -0
  49. package/src/nativeModuleUtils.ts +19 -8
  50. 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
- Prop("actionsWidth") { view: SwipeableView, width: Float ->
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
- Events("onSwipeProgress", "onSwipeStart", "onSwipeStateChange", "onSwipeEnd")
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.post { view.close(animated ?: true) }
77
+ view.postCommand { view.close(animated ?: true) }
64
78
  }
65
79
  AsyncFunction("open") { view: SwipeableView ->
66
- view.post { view.open() }
80
+ view.postCommand { view.open() }
67
81
  }
68
82
  AsyncFunction("cancel") { view: SwipeableView ->
69
- view.post { view.cancelGesture() }
83
+ view.postCommand { view.cancelGesture() }
70
84
  }
71
85
 
72
86
  AsyncFunction("handleGestureStart") { view: SwipeableView ->