react-native-swipeable-actions 0.1.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 (55) hide show
  1. package/README.md +250 -0
  2. package/android/build.gradle +99 -0
  3. package/android/src/main/AndroidManifest.xml +2 -0
  4. package/android/src/main/java/expo/modules/swipeable/SwipeConstants.kt +29 -0
  5. package/android/src/main/java/expo/modules/swipeable/SwipePhysics.kt +66 -0
  6. package/android/src/main/java/expo/modules/swipeable/SwipeableModule.kt +69 -0
  7. package/android/src/main/java/expo/modules/swipeable/SwipeableView.kt +951 -0
  8. package/build/Swipeable.d.ts +10 -0
  9. package/build/Swipeable.d.ts.map +1 -0
  10. package/build/Swipeable.js +114 -0
  11. package/build/Swipeable.js.map +1 -0
  12. package/build/Swipeable.types.d.ts +64 -0
  13. package/build/Swipeable.types.d.ts.map +1 -0
  14. package/build/Swipeable.types.js +3 -0
  15. package/build/Swipeable.types.js.map +1 -0
  16. package/build/SwipeableActions.d.ts +17 -0
  17. package/build/SwipeableActions.d.ts.map +1 -0
  18. package/build/SwipeableActions.js +31 -0
  19. package/build/SwipeableActions.js.map +1 -0
  20. package/build/SwipeableView.d.ts +10 -0
  21. package/build/SwipeableView.d.ts.map +1 -0
  22. package/build/SwipeableView.js +11 -0
  23. package/build/SwipeableView.js.map +1 -0
  24. package/build/constants.d.ts +11 -0
  25. package/build/constants.d.ts.map +1 -0
  26. package/build/constants.js +14 -0
  27. package/build/constants.js.map +1 -0
  28. package/build/index.d.ts +9 -0
  29. package/build/index.d.ts.map +1 -0
  30. package/build/index.js +21 -0
  31. package/build/index.js.map +1 -0
  32. package/build/nativeModuleUtils.d.ts +11 -0
  33. package/build/nativeModuleUtils.d.ts.map +1 -0
  34. package/build/nativeModuleUtils.js +49 -0
  35. package/build/nativeModuleUtils.js.map +1 -0
  36. package/build/swipeStateUtils.d.ts +16 -0
  37. package/build/swipeStateUtils.d.ts.map +1 -0
  38. package/build/swipeStateUtils.js +37 -0
  39. package/build/swipeStateUtils.js.map +1 -0
  40. package/expo-module.config.json +9 -0
  41. package/ios/Package.swift +28 -0
  42. package/ios/SwipeAnimationConfig.swift +27 -0
  43. package/ios/SwipePhysics.swift +66 -0
  44. package/ios/SwipeableModule.swift +84 -0
  45. package/ios/SwipeableView.swift +845 -0
  46. package/ios/react-native-swipeable-actions.podspec +22 -0
  47. package/package.json +85 -0
  48. package/src/Swipeable.tsx +195 -0
  49. package/src/Swipeable.types.ts +70 -0
  50. package/src/SwipeableActions.tsx +41 -0
  51. package/src/SwipeableView.tsx +20 -0
  52. package/src/constants.ts +11 -0
  53. package/src/index.ts +22 -0
  54. package/src/nativeModuleUtils.ts +57 -0
  55. package/src/swipeStateUtils.ts +55 -0
@@ -0,0 +1,66 @@
1
+ import Foundation
2
+ #if canImport(CoreGraphics)
3
+ import CoreGraphics
4
+ #endif
5
+
6
+ struct SwipePhysics {
7
+
8
+ static func applyRubberBand(
9
+ translation: CGFloat,
10
+ actionsWidth: CGFloat,
11
+ isLeading: Bool
12
+ ) -> CGFloat {
13
+ let divisor = SwipeAnimationConfig.rubberBandDivisor
14
+
15
+ if isLeading {
16
+ if translation > actionsWidth {
17
+ return actionsWidth + ((translation - actionsWidth) / divisor)
18
+ } else if translation < 0 {
19
+ return translation / divisor
20
+ }
21
+ } else {
22
+ if translation < -actionsWidth {
23
+ return -actionsWidth - ((abs(translation) - actionsWidth) / divisor)
24
+ } else if translation > 0 {
25
+ return translation / divisor
26
+ }
27
+ }
28
+ return translation
29
+ }
30
+
31
+ static func shouldSnapToOpen(
32
+ projectedTranslation: CGFloat,
33
+ actionsWidth: CGFloat,
34
+ threshold: CGFloat,
35
+ isLeading: Bool,
36
+ isCurrentlyOpen: Bool
37
+ ) -> Bool {
38
+ let thresholdDistance = actionsWidth * threshold
39
+
40
+ if isLeading {
41
+ return isCurrentlyOpen
42
+ ? projectedTranslation > -thresholdDistance
43
+ : projectedTranslation > thresholdDistance
44
+ } else {
45
+ return isCurrentlyOpen
46
+ ? projectedTranslation < thresholdDistance
47
+ : projectedTranslation < -thresholdDistance
48
+ }
49
+ }
50
+
51
+ static func projectFinalPosition(
52
+ translation: CGFloat,
53
+ velocity: CGFloat,
54
+ friction: CGFloat
55
+ ) -> CGFloat {
56
+ let factor = SwipeAnimationConfig.velocityProjectionFactor
57
+ return (translation * friction) + (velocity * friction * factor)
58
+ }
59
+
60
+ static func calculateSpringVelocity(from gestureVelocity: CGFloat) -> CGFloat {
61
+ guard abs(gestureVelocity) > 0 else { return 0 }
62
+ let normalizer = SwipeAnimationConfig.velocityNormalizer
63
+ let maxVelocity = SwipeAnimationConfig.maxNormalizedVelocity
64
+ return min(abs(gestureVelocity) / normalizer, maxVelocity)
65
+ }
66
+ }
@@ -0,0 +1,84 @@
1
+ import ExpoModulesCore
2
+
3
+ public class SwipeableModule: Module {
4
+ public func definition() -> ModuleDefinition {
5
+ Name("Swipeable")
6
+
7
+ // Module-level functions (by recyclingKey)
8
+ Function("openByKey") { (key: String) in
9
+ SwipeableView.openByKey(key)
10
+ }
11
+
12
+ Function("closeByKey") { (key: String, animated: Bool?) in
13
+ SwipeableView.closeByKey(key, animated: animated ?? true)
14
+ }
15
+
16
+ Function("closeAll") { (animated: Bool?) in
17
+ SwipeableView.closeAll(animated: animated ?? true)
18
+ }
19
+
20
+ View(SwipeableView.self) {
21
+ // Props
22
+ Prop("actionsWidth") { (view: SwipeableView, width: CGFloat) in
23
+ view.actionsWidth = width
24
+ }
25
+
26
+ Prop("actionsPosition") { (view: SwipeableView, position: String) in
27
+ view.actionsPosition = position
28
+ }
29
+
30
+ Prop("friction") { (view: SwipeableView, friction: CGFloat) in
31
+ view.friction = friction
32
+ }
33
+
34
+ Prop("threshold") { (view: SwipeableView, threshold: CGFloat) in
35
+ view.threshold = threshold
36
+ }
37
+
38
+ Prop("dragOffsetFromEdge") { (view: SwipeableView, offset: CGFloat) in
39
+ view.dragOffsetFromEdge = offset
40
+ }
41
+
42
+ Prop("recyclingKey") { (view: SwipeableView, key: String?) in
43
+ view.recyclingKey = key
44
+ }
45
+
46
+ Prop("autoClose") { (view: SwipeableView, autoClose: Bool) in
47
+ view.autoClose = autoClose
48
+ }
49
+
50
+ Prop("autoCloseTimeout") { (view: SwipeableView, timeout: CGFloat) in
51
+ view.autoCloseTimeout = timeout
52
+ }
53
+
54
+ // Events
55
+ Events("onSwipeProgress", "onSwipeStart", "onSwipeStateChange", "onSwipeEnd")
56
+
57
+ // Imperative methods
58
+ AsyncFunction("close") { (view: SwipeableView, animated: Bool?) in
59
+ DispatchQueue.main.async {
60
+ view.close(animated: animated ?? true)
61
+ }
62
+ }
63
+
64
+ AsyncFunction("open") { (view: SwipeableView) in
65
+ DispatchQueue.main.async {
66
+ view.open()
67
+ }
68
+ }
69
+
70
+ // Gesture handling methods (called from JS gesture handler)
71
+ AsyncFunction("handleGestureStart") { (view: SwipeableView) in
72
+ view.handleGestureStart()
73
+ }
74
+
75
+ AsyncFunction("handleGestureUpdate") { (view: SwipeableView, translationX: CGFloat, velocityX: CGFloat) in
76
+ view.handleGestureUpdate(translationX: translationX, velocityX: velocityX)
77
+ }
78
+
79
+ AsyncFunction("handleGestureEnd") { (view: SwipeableView, translationX: CGFloat, velocityX: CGFloat) in
80
+ view.handleGestureEnd(translationX: translationX, velocityX: velocityX)
81
+ }
82
+ }
83
+ }
84
+ }