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.
- package/README.md +250 -0
- package/android/build.gradle +99 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeConstants.kt +29 -0
- package/android/src/main/java/expo/modules/swipeable/SwipePhysics.kt +66 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeableModule.kt +69 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeableView.kt +951 -0
- package/build/Swipeable.d.ts +10 -0
- package/build/Swipeable.d.ts.map +1 -0
- package/build/Swipeable.js +114 -0
- package/build/Swipeable.js.map +1 -0
- package/build/Swipeable.types.d.ts +64 -0
- package/build/Swipeable.types.d.ts.map +1 -0
- package/build/Swipeable.types.js +3 -0
- package/build/Swipeable.types.js.map +1 -0
- package/build/SwipeableActions.d.ts +17 -0
- package/build/SwipeableActions.d.ts.map +1 -0
- package/build/SwipeableActions.js +31 -0
- package/build/SwipeableActions.js.map +1 -0
- package/build/SwipeableView.d.ts +10 -0
- package/build/SwipeableView.d.ts.map +1 -0
- package/build/SwipeableView.js +11 -0
- package/build/SwipeableView.js.map +1 -0
- package/build/constants.d.ts +11 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +14 -0
- package/build/constants.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +21 -0
- package/build/index.js.map +1 -0
- package/build/nativeModuleUtils.d.ts +11 -0
- package/build/nativeModuleUtils.d.ts.map +1 -0
- package/build/nativeModuleUtils.js +49 -0
- package/build/nativeModuleUtils.js.map +1 -0
- package/build/swipeStateUtils.d.ts +16 -0
- package/build/swipeStateUtils.d.ts.map +1 -0
- package/build/swipeStateUtils.js +37 -0
- package/build/swipeStateUtils.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/Package.swift +28 -0
- package/ios/SwipeAnimationConfig.swift +27 -0
- package/ios/SwipePhysics.swift +66 -0
- package/ios/SwipeableModule.swift +84 -0
- package/ios/SwipeableView.swift +845 -0
- package/ios/react-native-swipeable-actions.podspec +22 -0
- package/package.json +85 -0
- package/src/Swipeable.tsx +195 -0
- package/src/Swipeable.types.ts +70 -0
- package/src/SwipeableActions.tsx +41 -0
- package/src/SwipeableView.tsx +20 -0
- package/src/constants.ts +11 -0
- package/src/index.ts +22 -0
- package/src/nativeModuleUtils.ts +57 -0
- 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
|
+
}
|