@react-native-ama/core 2.0.0-beta.1 → 2.0.0-beta.2

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.
@@ -0,0 +1,107 @@
1
+ import UIKit
2
+ import UIKit.UIGestureRecognizerSubclass
3
+
4
+
5
+ /**
6
+ * A plain `UITapGestureRecognizer.location(in:)` queried from the `@objc`
7
+ * action target can come back as `(0, 0)` on device: this recognizer sits on
8
+ * the window alongside RN's own touch handler, and by the time our action
9
+ * fires, UIKit's touch bookkeeping for this recognizer may already be reset.
10
+ * Capturing the location eagerly in `touchesEnded`, before that happens,
11
+ * gives a reliable value.
12
+ */
13
+ class WindowTapGestureRecognizer: UITapGestureRecognizer {
14
+ private(set) var capturedLocation: CGPoint = .zero
15
+
16
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
17
+ if let touch = touches.first, let window = self.view as? UIWindow {
18
+ capturedLocation = touch.location(in: window)
19
+ }
20
+ super.touchesEnded(touches, with: event)
21
+ }
22
+ }
23
+
24
+ class GlobalTapProbeGestureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate {
25
+ private var downPoint: CGPoint = .zero
26
+ private let tapThreshold: CGFloat = 20.0 // Max movement (in points) for a "tap"
27
+
28
+ var onTapDetected: ((UIView, UIView) -> Void)?
29
+
30
+ override init(target: Any?, action: Selector?) {
31
+ super.init(target: target, action: action)
32
+
33
+ cancelsTouchesInView = false
34
+ delaysTouchesBegan = false
35
+ delaysTouchesEnded = false
36
+
37
+ self.delegate = self
38
+ }
39
+
40
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
41
+ super.touchesBegan(touches, with: event)
42
+
43
+ if let touch = touches.first {
44
+ downPoint = touch.location(in: self.view)
45
+ self.state = .began // Move to "began" state
46
+ }
47
+ }
48
+
49
+ override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
50
+ super.touchesMoved(touches, with: event)
51
+
52
+ if let touch = touches.first {
53
+ let currentPoint = touch.location(in: self.view)
54
+ let distance = hypot(currentPoint.x - downPoint.x, currentPoint.y - downPoint.y)
55
+ if distance > tapThreshold {
56
+ self.state = .failed
57
+ }
58
+ }
59
+ }
60
+
61
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
62
+ super.touchesEnded(touches, with: event)
63
+
64
+ guard self.state != .failed,
65
+ let touch = touches.first,
66
+ let window = self.view as? UIWindow else {
67
+
68
+ self.state = (self.state == .began) ? .ended : .failed
69
+ return
70
+ }
71
+
72
+ let upPoint = touch.location(in: window)
73
+
74
+ let distance = hypot(upPoint.x - downPoint.x, upPoint.y - downPoint.y)
75
+
76
+ if distance < tapThreshold {
77
+ self.state = .recognized // Mark as recognized
78
+
79
+ if let tappedView = window.hitTest(upPoint, with: event) {
80
+
81
+ let isPressable = tappedView.isPressable
82
+ let isAccessible = tappedView.isAccessibilityElement
83
+
84
+ if isPressable && isAccessible {
85
+ if let rootView = window.rootViewController?.view {
86
+ onTapDetected?(tappedView, rootView)
87
+ }
88
+ }
89
+ }
90
+ self.state = .ended
91
+ } else {
92
+ self.state = .failed
93
+ }
94
+ }
95
+
96
+ override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
97
+ super.touchesCancelled(touches, with: event)
98
+ self.state = .failed
99
+ }
100
+
101
+ public func gestureRecognizer(
102
+ _ gestureRecognizer: UIGestureRecognizer,
103
+ shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
104
+ ) -> Bool {
105
+ return true
106
+ }
107
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@react-native-ama/core",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Accessible Mobile App Library for React Native",
5
5
  "sideEffects": false,
6
+ "types": "./dist/index.d.ts",
6
7
  "exports": {
7
8
  ".": {
8
9
  "types": "./dist/index.d.ts",
@@ -44,7 +45,12 @@
44
45
  },
45
46
  "files": [
46
47
  "src",
47
- "dist"
48
+ "dist",
49
+ "ama.config.json",
50
+ "expo-module.config.json",
51
+ "ios",
52
+ "android",
53
+ "!android/build"
48
54
  ],
49
55
  "scripts": {
50
56
  "build": "rm -rf dist && ../../node_modules/.bin/tsc -p ./tsconfig.build.json",