react-native-ios-translate-sheet 1.3.2 → 1.4.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 +35 -6
- package/android/generated/java/com/facebook/react/viewmanagers/IOSTranslateSheetViewManagerDelegate.java +6 -0
- package/android/generated/java/com/facebook/react/viewmanagers/IOSTranslateSheetViewManagerInterface.java +2 -0
- package/android/generated/jni/react/renderer/components/RNIOSTranslateSheetViewSpec/Props.cpp +3 -1
- package/android/generated/jni/react/renderer/components/RNIOSTranslateSheetViewSpec/Props.h +2 -0
- package/ios/IOSTranslateSheet.swift +32 -2
- package/ios/IOSTranslateSheetProvider.swift +13 -1
- package/ios/IOSTranslateSheetView.mm +7 -1
- package/ios/IOSTranslateSheetViewManager.mm +2 -0
- package/ios/generated/RNIOSTranslateSheetViewSpec/Props.cpp +3 -1
- package/ios/generated/RNIOSTranslateSheetViewSpec/Props.h +2 -0
- package/lib/commonjs/IOSTranslateSheetViewNativeComponent.ts +6 -1
- package/lib/commonjs/TranslateContext.js +5 -2
- package/lib/commonjs/TranslateContext.js.map +1 -1
- package/lib/commonjs/hooks/useInternalTranslate.js +13 -4
- package/lib/commonjs/hooks/useInternalTranslate.js.map +1 -1
- package/lib/module/IOSTranslateSheetViewNativeComponent.ts +6 -1
- package/lib/module/TranslateContext.js +5 -2
- package/lib/module/TranslateContext.js.map +1 -1
- package/lib/module/hooks/useInternalTranslate.js +13 -4
- package/lib/module/hooks/useInternalTranslate.js.map +1 -1
- package/lib/typescript/IOSTranslateSheetViewNativeComponent.d.ts +3 -1
- package/lib/typescript/IOSTranslateSheetViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/TranslateContext.d.ts +7 -1
- package/lib/typescript/TranslateContext.d.ts.map +1 -1
- package/lib/typescript/hooks/useInternalTranslate.d.ts +6 -1
- package/lib/typescript/hooks/useInternalTranslate.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/IOSTranslateSheetViewNativeComponent.ts +6 -1
- package/src/TranslateContext.tsx +15 -5
- package/src/hooks/useInternalTranslate.tsx +10 -6
package/README.md
CHANGED
|
@@ -74,7 +74,36 @@ function MyComponent() {
|
|
|
74
74
|
const { presentIOSTranslateSheet } = useIOSTranslateSheet();
|
|
75
75
|
|
|
76
76
|
const handleTranslate = () => {
|
|
77
|
-
presentIOSTranslateSheet(
|
|
77
|
+
presentIOSTranslateSheet({
|
|
78
|
+
text: 'Text to translate',
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Button
|
|
84
|
+
title="Translate"
|
|
85
|
+
onPress={handleTranslate}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### iPad
|
|
92
|
+
|
|
93
|
+
On iPad, the translation sheet needs an anchor point to display correctly (it's optional, and by default the sheet will be displayed at the bottom of the screen). You can specify the position where the sheet should appear by providing a gesture event to `presentIOSTranslateSheet`:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import type { GestureResponderEvent } from "react-native";
|
|
97
|
+
import { useIOSTranslateSheet } from 'react-native-ios-translate-sheet';
|
|
98
|
+
|
|
99
|
+
function MyComponent() {
|
|
100
|
+
const { presentIOSTranslateSheet } = useIOSTranslateSheet();
|
|
101
|
+
|
|
102
|
+
const handleTranslate = (event: GestureResponderEvent) => {
|
|
103
|
+
presentIOSTranslateSheet({
|
|
104
|
+
text: 'Text to translate',
|
|
105
|
+
gestureEvent: event,
|
|
106
|
+
});
|
|
78
107
|
};
|
|
79
108
|
|
|
80
109
|
return (
|
|
@@ -102,13 +131,13 @@ To handle translated text, provide a callback function as the second parameter t
|
|
|
102
131
|
const { presentIOSTranslateSheet } = useIOSTranslateSheet();
|
|
103
132
|
|
|
104
133
|
const handleTranslate = () => {
|
|
105
|
-
presentIOSTranslateSheet(
|
|
106
|
-
'Hello, how are you?',
|
|
107
|
-
(translatedText) => {
|
|
134
|
+
presentIOSTranslateSheet({
|
|
135
|
+
text: 'Hello, how are you?',
|
|
136
|
+
replacementAction: (translatedText) => {
|
|
108
137
|
// Handle the translated text here
|
|
109
138
|
setTranslatedContent(translatedText);
|
|
110
|
-
}
|
|
111
|
-
);
|
|
139
|
+
},
|
|
140
|
+
});
|
|
112
141
|
};
|
|
113
142
|
```
|
|
114
143
|
|
|
@@ -31,6 +31,12 @@ public class IOSTranslateSheetViewManagerDelegate<T extends View, U extends Base
|
|
|
31
31
|
case "hasReplacementAction":
|
|
32
32
|
mViewManager.setHasReplacementAction(view, value == null ? false : (boolean) value);
|
|
33
33
|
break;
|
|
34
|
+
case "translateAnchorPointX":
|
|
35
|
+
mViewManager.setTranslateAnchorPointX(view, value == null ? 0f : ((Double) value).doubleValue());
|
|
36
|
+
break;
|
|
37
|
+
case "translateAnchorPointY":
|
|
38
|
+
mViewManager.setTranslateAnchorPointY(view, value == null ? 0f : ((Double) value).doubleValue());
|
|
39
|
+
break;
|
|
34
40
|
default:
|
|
35
41
|
super.setProperty(view, propName, value);
|
|
36
42
|
}
|
|
@@ -17,4 +17,6 @@ public interface IOSTranslateSheetViewManagerInterface<T extends View> extends V
|
|
|
17
17
|
void setText(T view, @Nullable String value);
|
|
18
18
|
void setIsPresented(T view, boolean value);
|
|
19
19
|
void setHasReplacementAction(T view, boolean value);
|
|
20
|
+
void setTranslateAnchorPointX(T view, double value);
|
|
21
|
+
void setTranslateAnchorPointY(T view, double value);
|
|
20
22
|
}
|
package/android/generated/jni/react/renderer/components/RNIOSTranslateSheetViewSpec/Props.cpp
CHANGED
|
@@ -21,7 +21,9 @@ IOSTranslateSheetViewProps::IOSTranslateSheetViewProps(
|
|
|
21
21
|
|
|
22
22
|
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
|
|
23
23
|
isPresented(convertRawProp(context, rawProps, "isPresented", sourceProps.isPresented, {false})),
|
|
24
|
-
hasReplacementAction(convertRawProp(context, rawProps, "hasReplacementAction", sourceProps.hasReplacementAction, {false}))
|
|
24
|
+
hasReplacementAction(convertRawProp(context, rawProps, "hasReplacementAction", sourceProps.hasReplacementAction, {false})),
|
|
25
|
+
translateAnchorPointX(convertRawProp(context, rawProps, "translateAnchorPointX", sourceProps.translateAnchorPointX, {0.0})),
|
|
26
|
+
translateAnchorPointY(convertRawProp(context, rawProps, "translateAnchorPointY", sourceProps.translateAnchorPointY, {0.0}))
|
|
25
27
|
{}
|
|
26
28
|
|
|
27
29
|
} // namespace facebook::react
|
|
@@ -24,6 +24,8 @@ class IOSTranslateSheetViewProps final : public ViewProps {
|
|
|
24
24
|
std::string text{};
|
|
25
25
|
bool isPresented{false};
|
|
26
26
|
bool hasReplacementAction{false};
|
|
27
|
+
double translateAnchorPointX{0.0};
|
|
28
|
+
double translateAnchorPointY{0.0};
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
} // namespace facebook::react
|
|
@@ -5,12 +5,15 @@ class Props: ObservableObject {
|
|
|
5
5
|
@Published var text: String = ""
|
|
6
6
|
@Published var isPresented: Bool = false
|
|
7
7
|
@Published var hasReplacementAction: Bool = false
|
|
8
|
+
@Published var translateAnchorPointX: CGFloat?
|
|
9
|
+
@Published var translateAnchorPointY: CGFloat?
|
|
8
10
|
@Published var onHide: () -> Void = {}
|
|
9
11
|
@Published var onReplacementAction: (String) -> Void = { _ in }
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
struct IOSTranslateSheet: View {
|
|
13
15
|
@ObservedObject var props: Props
|
|
16
|
+
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
|
14
17
|
|
|
15
18
|
var body: some View {
|
|
16
19
|
if #available(iOS 17.4, *) {
|
|
@@ -19,8 +22,8 @@ struct IOSTranslateSheet: View {
|
|
|
19
22
|
.translationPresentation(
|
|
20
23
|
isPresented: $props.isPresented,
|
|
21
24
|
text: props.text,
|
|
22
|
-
attachmentAnchor:
|
|
23
|
-
arrowEdge:
|
|
25
|
+
attachmentAnchor: getAttachmentAnchor(),
|
|
26
|
+
arrowEdge: getArrowEdge(),
|
|
24
27
|
replacementAction: props.hasReplacementAction ? props.onReplacementAction : nil
|
|
25
28
|
)
|
|
26
29
|
.onChange(of: props.isPresented) { oldValue, newValue in
|
|
@@ -30,4 +33,31 @@ struct IOSTranslateSheet: View {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
36
|
+
|
|
37
|
+
@available(iOS 17.4, *)
|
|
38
|
+
private func getAttachmentAnchor() -> PopoverAttachmentAnchor {
|
|
39
|
+
if horizontalSizeClass == .regular, let pointX = props.translateAnchorPointX, let pointY = props.translateAnchorPointY {
|
|
40
|
+
let screenSize = UIScreen.main.bounds.size
|
|
41
|
+
let normalizedPoint = UnitPoint(
|
|
42
|
+
x: pointX / screenSize.width,
|
|
43
|
+
y: pointY / screenSize.height
|
|
44
|
+
)
|
|
45
|
+
if (normalizedPoint.x == 0 && normalizedPoint.y == 0) {
|
|
46
|
+
return .point(.bottom)
|
|
47
|
+
}
|
|
48
|
+
return .point(normalizedPoint)
|
|
49
|
+
}
|
|
50
|
+
return .point(.bottom)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@available(iOS 17.4, *)
|
|
54
|
+
private func getArrowEdge() -> Edge {
|
|
55
|
+
if horizontalSizeClass == .regular, let pointY = props.translateAnchorPointY {
|
|
56
|
+
if pointY != 0 && pointY < UIScreen.main.bounds.height / 2 {
|
|
57
|
+
return .top
|
|
58
|
+
}
|
|
59
|
+
return .bottom
|
|
60
|
+
}
|
|
61
|
+
return .top
|
|
62
|
+
}
|
|
33
63
|
}
|
|
@@ -38,6 +38,18 @@ public typealias RCTBubblingEventBlock = @convention(block) (_ body: [AnyHashabl
|
|
|
38
38
|
props.hasReplacementAction = hasReplacementAction
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
@objc public var translateAnchorPointX: NSNumber = 0 {
|
|
43
|
+
didSet {
|
|
44
|
+
props.translateAnchorPointX = CGFloat(translateAnchorPointX.doubleValue)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@objc public var translateAnchorPointY: NSNumber = 0 {
|
|
49
|
+
didSet {
|
|
50
|
+
props.translateAnchorPointY = CGFloat(translateAnchorPointY.doubleValue)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
41
53
|
|
|
42
54
|
@objc public var onHide: RCTBubblingEventBlock? {
|
|
43
55
|
didSet {
|
|
@@ -78,4 +90,4 @@ public typealias RCTBubblingEventBlock = @convention(block) (_ body: [AnyHashabl
|
|
|
78
90
|
reactAddController(toClosestParent: hostingController)
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
|
-
}
|
|
93
|
+
}
|
|
@@ -71,6 +71,12 @@ using namespace facebook::react;
|
|
|
71
71
|
if (oldViewProps.hasReplacementAction != newViewProps.hasReplacementAction) {
|
|
72
72
|
_view.hasReplacementAction = newViewProps.hasReplacementAction;
|
|
73
73
|
}
|
|
74
|
+
if (oldViewProps.translateAnchorPointX != newViewProps.translateAnchorPointX) {
|
|
75
|
+
_view.translateAnchorPointX = @(newViewProps.translateAnchorPointX);
|
|
76
|
+
}
|
|
77
|
+
if (oldViewProps.translateAnchorPointY != newViewProps.translateAnchorPointY) {
|
|
78
|
+
_view.translateAnchorPointY = @(newViewProps.translateAnchorPointY);
|
|
79
|
+
}
|
|
74
80
|
|
|
75
81
|
[super updateProps:props oldProps:oldProps];
|
|
76
82
|
}
|
|
@@ -81,4 +87,4 @@ Class<RCTComponentViewProtocol> IOSTranslateSheetViewCls(void)
|
|
|
81
87
|
{
|
|
82
88
|
return IOSTranslateSheetView.class;
|
|
83
89
|
}
|
|
84
|
-
#endif
|
|
90
|
+
#endif
|
|
@@ -31,6 +31,8 @@ RCT_EXPORT_MODULE(IOSTranslateSheetView)
|
|
|
31
31
|
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
|
|
32
32
|
RCT_EXPORT_VIEW_PROPERTY(isPresented, BOOL)
|
|
33
33
|
RCT_EXPORT_VIEW_PROPERTY(hasReplacementAction, BOOL)
|
|
34
|
+
RCT_EXPORT_VIEW_PROPERTY(translateAnchorPointX, NSNumber)
|
|
35
|
+
RCT_EXPORT_VIEW_PROPERTY(translateAnchorPointY, NSNumber)
|
|
34
36
|
RCT_EXPORT_VIEW_PROPERTY(onHide, RCTDirectEventBlock)
|
|
35
37
|
RCT_EXPORT_VIEW_PROPERTY(onReplacementAction, RCTDirectEventBlock)
|
|
36
38
|
|
|
@@ -21,7 +21,9 @@ IOSTranslateSheetViewProps::IOSTranslateSheetViewProps(
|
|
|
21
21
|
|
|
22
22
|
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
|
|
23
23
|
isPresented(convertRawProp(context, rawProps, "isPresented", sourceProps.isPresented, {false})),
|
|
24
|
-
hasReplacementAction(convertRawProp(context, rawProps, "hasReplacementAction", sourceProps.hasReplacementAction, {false}))
|
|
24
|
+
hasReplacementAction(convertRawProp(context, rawProps, "hasReplacementAction", sourceProps.hasReplacementAction, {false})),
|
|
25
|
+
translateAnchorPointX(convertRawProp(context, rawProps, "translateAnchorPointX", sourceProps.translateAnchorPointX, {0.0})),
|
|
26
|
+
translateAnchorPointY(convertRawProp(context, rawProps, "translateAnchorPointY", sourceProps.translateAnchorPointY, {0.0}))
|
|
25
27
|
{}
|
|
26
28
|
|
|
27
29
|
} // namespace facebook::react
|
|
@@ -24,6 +24,8 @@ class IOSTranslateSheetViewProps final : public ViewProps {
|
|
|
24
24
|
std::string text{};
|
|
25
25
|
bool isPresented{false};
|
|
26
26
|
bool hasReplacementAction{false};
|
|
27
|
+
double translateAnchorPointX{0.0};
|
|
28
|
+
double translateAnchorPointY{0.0};
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
} // namespace facebook::react
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DirectEventHandler,
|
|
4
|
+
Double,
|
|
5
|
+
} from "react-native/Libraries/Types/CodegenTypes";
|
|
3
6
|
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
4
7
|
|
|
5
8
|
export interface OnReplacementActionEvent {
|
|
@@ -10,6 +13,8 @@ interface IOSTranslateSheetProps extends ViewProps {
|
|
|
10
13
|
text: string;
|
|
11
14
|
isPresented: boolean;
|
|
12
15
|
hasReplacementAction: boolean;
|
|
16
|
+
translateAnchorPointX?: Double;
|
|
17
|
+
translateAnchorPointY?: Double;
|
|
13
18
|
onHide: DirectEventHandler<null>;
|
|
14
19
|
onReplacementAction?: DirectEventHandler<OnReplacementActionEvent>;
|
|
15
20
|
}
|
|
@@ -20,7 +20,8 @@ const IOSTranslateSheetProvider = ({
|
|
|
20
20
|
text,
|
|
21
21
|
hideTranslateSheet,
|
|
22
22
|
isSupported,
|
|
23
|
-
replacementAction
|
|
23
|
+
replacementAction,
|
|
24
|
+
anchorPoint
|
|
24
25
|
} = (0, _useInternalTranslate.useInternalTranslateSheet)();
|
|
25
26
|
const onReplacementAction = event => {
|
|
26
27
|
replacementAction?.(event.nativeEvent.text);
|
|
@@ -36,7 +37,9 @@ const IOSTranslateSheetProvider = ({
|
|
|
36
37
|
onHide: hideTranslateSheet,
|
|
37
38
|
style: _reactNative.StyleSheet.absoluteFillObject,
|
|
38
39
|
hasReplacementAction: !!replacementAction,
|
|
39
|
-
onReplacementAction: onReplacementAction
|
|
40
|
+
onReplacementAction: onReplacementAction,
|
|
41
|
+
translateAnchorPointX: anchorPoint.x,
|
|
42
|
+
translateAnchorPointY: anchorPoint.y
|
|
40
43
|
}), children]
|
|
41
44
|
});
|
|
42
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_IOSTranslateSheetViewNativeComponent","_interopRequireDefault","_useInternalTranslate","_jsxRuntime","e","__esModule","default","TranslateContext","createContext","IOSTranslateSheetProvider","children","presentIOSTranslateSheet","isIOSTranslateSheetPresented","text","hideTranslateSheet","isSupported","replacementAction","useInternalTranslateSheet","onReplacementAction","event","nativeEvent","jsxs","Provider","value","jsx","isPresented","onHide","style","StyleSheet","absoluteFillObject","hasReplacementAction","exports","useIOSTranslateSheet","context","useContext","Error"],"sourceRoot":"../../src","sources":["TranslateContext.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_IOSTranslateSheetViewNativeComponent","_interopRequireDefault","_useInternalTranslate","_jsxRuntime","e","__esModule","default","TranslateContext","createContext","IOSTranslateSheetProvider","children","presentIOSTranslateSheet","isIOSTranslateSheetPresented","text","hideTranslateSheet","isSupported","replacementAction","anchorPoint","useInternalTranslateSheet","onReplacementAction","event","nativeEvent","jsxs","Provider","value","jsx","isPresented","onHide","style","StyleSheet","absoluteFillObject","hasReplacementAction","translateAnchorPointX","x","translateAnchorPointY","y","exports","useIOSTranslateSheet","context","useContext","Error"],"sourceRoot":"../../src","sources":["TranslateContext.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAKA,IAAAE,qCAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,qBAAA,GAAAJ,OAAA;AAAyE,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAazE,MAAMG,gBAAgB,gBAAG,IAAAC,oBAAa,EAA8B,IAAI,CAAC;AAElE,MAAMC,yBAAyB,GAAGA,CAAC;EACxCC;AACuB,CAAC,KAAK;EAC7B,MAAM;IACJC,wBAAwB;IACxBC,4BAA4B;IAC5BC,IAAI;IACJC,kBAAkB;IAClBC,WAAW;IACXC,iBAAiB;IACjBC;EACF,CAAC,GAAG,IAAAC,+CAAyB,EAAC,CAAC;EAE/B,MAAMC,mBAAmB,GACvBC,KAAqD,IAClD;IACHJ,iBAAiB,GAAGI,KAAK,CAACC,WAAW,CAACR,IAAI,CAAC;EAC7C,CAAC;EAED,oBACE,IAAAV,WAAA,CAAAmB,IAAA,EAACf,gBAAgB,CAACgB,QAAQ;IACxBC,KAAK,EAAE;MACLb,wBAAwB;MACxBI;IACF,CAAE;IAAAL,QAAA,gBAEF,IAAAP,WAAA,CAAAsB,GAAA,EAACzB,qCAAA,CAAAM,OAAiB;MAChBO,IAAI,EAAEA,IAAK;MACXa,WAAW,EAAEd,4BAA6B;MAC1Ce,MAAM,EAAEb,kBAAmB;MAC3Bc,KAAK,EAAEC,uBAAU,CAACC,kBAAmB;MACrCC,oBAAoB,EAAE,CAAC,CAACf,iBAAkB;MAC1CG,mBAAmB,EAAEA,mBAAoB;MACzCa,qBAAqB,EAAEf,WAAW,CAACgB,CAAE;MACrCC,qBAAqB,EAAEjB,WAAW,CAACkB;IAAE,CACtC,CAAC,EACDzB,QAAQ;EAAA,CACgB,CAAC;AAEhC,CAAC;AAAC0B,OAAA,CAAA3B,yBAAA,GAAAA,yBAAA;AAEK,MAAM4B,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAAChC,gBAAgB,CAAC;EAC5C,IAAI,CAAC+B,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CACb,sEACF,CAAC;EACH;EACA,OAAOF,OAAO;AAChB,CAAC;AAACF,OAAA,CAAAC,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -11,9 +11,17 @@ const useInternalTranslateSheet = () => {
|
|
|
11
11
|
const [isIOSTranslateSheetPresented, setIsIOSTranslateSheetPresented] = (0, _react.useState)(false);
|
|
12
12
|
const textRef = (0, _react.useRef)("");
|
|
13
13
|
const replacementActionRef = (0, _react.useRef)(undefined);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const anchorPoint = (0, _react.useRef)({
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0
|
|
17
|
+
});
|
|
18
|
+
const presentIOSTranslateSheet = params => {
|
|
19
|
+
textRef.current = params.text;
|
|
20
|
+
replacementActionRef.current = params.replacementAction;
|
|
21
|
+
anchorPoint.current = {
|
|
22
|
+
x: params.gestureEvent?.nativeEvent.pageX || 0,
|
|
23
|
+
y: params.gestureEvent?.nativeEvent.pageY || 0
|
|
24
|
+
};
|
|
17
25
|
setIsIOSTranslateSheetPresented(true);
|
|
18
26
|
};
|
|
19
27
|
const hideTranslateSheet = () => {
|
|
@@ -25,7 +33,8 @@ const useInternalTranslateSheet = () => {
|
|
|
25
33
|
hideTranslateSheet,
|
|
26
34
|
text: textRef.current,
|
|
27
35
|
isSupported,
|
|
28
|
-
replacementAction: replacementActionRef.current
|
|
36
|
+
replacementAction: replacementActionRef.current,
|
|
37
|
+
anchorPoint: anchorPoint.current
|
|
29
38
|
};
|
|
30
39
|
};
|
|
31
40
|
exports.useInternalTranslateSheet = useInternalTranslateSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","isSupported","Platform","OS","Number","parseFloat","String","Version","useInternalTranslateSheet","isIOSTranslateSheetPresented","setIsIOSTranslateSheetPresented","useState","textRef","useRef","replacementActionRef","undefined","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","isSupported","Platform","OS","Number","parseFloat","String","Version","useInternalTranslateSheet","isIOSTranslateSheetPresented","setIsIOSTranslateSheetPresented","useState","textRef","useRef","replacementActionRef","undefined","anchorPoint","x","y","presentIOSTranslateSheet","params","current","text","replacementAction","gestureEvent","nativeEvent","pageX","pageY","hideTranslateSheet","exports"],"sourceRoot":"../../../src","sources":["hooks/useInternalTranslate.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,MAAME,WAAW,GACfC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAIC,MAAM,CAACC,UAAU,CAACC,MAAM,CAACJ,qBAAQ,CAACK,OAAO,CAAC,CAAC,IAAI,IAAI;AAEvE,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAM,CAACC,4BAA4B,EAAEC,+BAA+B,CAAC,GACnE,IAAAC,eAAQ,EAAC,KAAK,CAAC;EACjB,MAAMC,OAAO,GAAG,IAAAC,aAAM,EAAC,EAAE,CAAC;EAC1B,MAAMC,oBAAoB,GAAG,IAAAD,aAAM,EAAyBE,SAAS,CAAC;EACtE,MAAMC,WAAW,GAAG,IAAAH,aAAM,EAA2B;IAAEI,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC,CAAC;EAEpE,MAAMC,wBAAwB,GAAIC,MAAsC,IAAK;IAC3ER,OAAO,CAACS,OAAO,GAAGD,MAAM,CAACE,IAAI;IAC7BR,oBAAoB,CAACO,OAAO,GAAGD,MAAM,CAACG,iBAAiB;IACvDP,WAAW,CAACK,OAAO,GAAG;MACpBJ,CAAC,EAAEG,MAAM,CAACI,YAAY,EAAEC,WAAW,CAACC,KAAK,IAAI,CAAC;MAC9CR,CAAC,EAAEE,MAAM,CAACI,YAAY,EAAEC,WAAW,CAACE,KAAK,IAAI;IAC/C,CAAC;IACDjB,+BAA+B,CAAC,IAAI,CAAC;EACvC,CAAC;EAED,MAAMkB,kBAAkB,GAAGA,CAAA,KAAM;IAC/BlB,+BAA+B,CAAC,KAAK,CAAC;EACxC,CAAC;EAED,OAAO;IACLD,4BAA4B;IAC5BU,wBAAwB;IACxBS,kBAAkB;IAClBN,IAAI,EAAEV,OAAO,CAACS,OAAO;IACrBpB,WAAW;IACXsB,iBAAiB,EAAET,oBAAoB,CAACO,OAAO;IAC/CL,WAAW,EAAEA,WAAW,CAACK;EAC3B,CAAC;AACH,CAAC;AAACQ,OAAA,CAAArB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DirectEventHandler,
|
|
4
|
+
Double,
|
|
5
|
+
} from "react-native/Libraries/Types/CodegenTypes";
|
|
3
6
|
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
4
7
|
|
|
5
8
|
export interface OnReplacementActionEvent {
|
|
@@ -10,6 +13,8 @@ interface IOSTranslateSheetProps extends ViewProps {
|
|
|
10
13
|
text: string;
|
|
11
14
|
isPresented: boolean;
|
|
12
15
|
hasReplacementAction: boolean;
|
|
16
|
+
translateAnchorPointX?: Double;
|
|
17
|
+
translateAnchorPointY?: Double;
|
|
13
18
|
onHide: DirectEventHandler<null>;
|
|
14
19
|
onReplacementAction?: DirectEventHandler<OnReplacementActionEvent>;
|
|
15
20
|
}
|
|
@@ -15,7 +15,8 @@ export const IOSTranslateSheetProvider = ({
|
|
|
15
15
|
text,
|
|
16
16
|
hideTranslateSheet,
|
|
17
17
|
isSupported,
|
|
18
|
-
replacementAction
|
|
18
|
+
replacementAction,
|
|
19
|
+
anchorPoint
|
|
19
20
|
} = useInternalTranslateSheet();
|
|
20
21
|
const onReplacementAction = event => {
|
|
21
22
|
replacementAction?.(event.nativeEvent.text);
|
|
@@ -31,7 +32,9 @@ export const IOSTranslateSheetProvider = ({
|
|
|
31
32
|
onHide: hideTranslateSheet,
|
|
32
33
|
style: StyleSheet.absoluteFillObject,
|
|
33
34
|
hasReplacementAction: !!replacementAction,
|
|
34
|
-
onReplacementAction: onReplacementAction
|
|
35
|
+
onReplacementAction: onReplacementAction,
|
|
36
|
+
translateAnchorPointX: anchorPoint.x,
|
|
37
|
+
translateAnchorPointY: anchorPoint.y
|
|
35
38
|
}), children]
|
|
36
39
|
});
|
|
37
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","StyleSheet","IOSTranslateSheet","useInternalTranslateSheet","jsx","_jsx","jsxs","_jsxs","TranslateContext","IOSTranslateSheetProvider","children","presentIOSTranslateSheet","isIOSTranslateSheetPresented","text","hideTranslateSheet","isSupported","replacementAction","onReplacementAction","event","nativeEvent","Provider","value","isPresented","onHide","style","absoluteFillObject","hasReplacementAction","useIOSTranslateSheet","context","Error"],"sourceRoot":"../../src","sources":["TranslateContext.tsx"],"mappings":";;AAAA,SAAyBA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjE,
|
|
1
|
+
{"version":3,"names":["createContext","useContext","StyleSheet","IOSTranslateSheet","useInternalTranslateSheet","jsx","_jsx","jsxs","_jsxs","TranslateContext","IOSTranslateSheetProvider","children","presentIOSTranslateSheet","isIOSTranslateSheetPresented","text","hideTranslateSheet","isSupported","replacementAction","anchorPoint","onReplacementAction","event","nativeEvent","Provider","value","isPresented","onHide","style","absoluteFillObject","hasReplacementAction","translateAnchorPointX","x","translateAnchorPointY","y","useIOSTranslateSheet","context","Error"],"sourceRoot":"../../src","sources":["TranslateContext.tsx"],"mappings":";;AAAA,SAAyBA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjE,SAGEC,UAAU,QACL,cAAc;AACrB,OAAOC,iBAAiB,MAEjB,wCAAwC;AAC/C,SAASC,yBAAyB,QAAQ,8BAA8B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAazE,MAAMC,gBAAgB,gBAAGT,aAAa,CAA8B,IAAI,CAAC;AAEzE,OAAO,MAAMU,yBAAyB,GAAGA,CAAC;EACxCC;AACuB,CAAC,KAAK;EAC7B,MAAM;IACJC,wBAAwB;IACxBC,4BAA4B;IAC5BC,IAAI;IACJC,kBAAkB;IAClBC,WAAW;IACXC,iBAAiB;IACjBC;EACF,CAAC,GAAGd,yBAAyB,CAAC,CAAC;EAE/B,MAAMe,mBAAmB,GACvBC,KAAqD,IAClD;IACHH,iBAAiB,GAAGG,KAAK,CAACC,WAAW,CAACP,IAAI,CAAC;EAC7C,CAAC;EAED,oBACEN,KAAA,CAACC,gBAAgB,CAACa,QAAQ;IACxBC,KAAK,EAAE;MACLX,wBAAwB;MACxBI;IACF,CAAE;IAAAL,QAAA,gBAEFL,IAAA,CAACH,iBAAiB;MAChBW,IAAI,EAAEA,IAAK;MACXU,WAAW,EAAEX,4BAA6B;MAC1CY,MAAM,EAAEV,kBAAmB;MAC3BW,KAAK,EAAExB,UAAU,CAACyB,kBAAmB;MACrCC,oBAAoB,EAAE,CAAC,CAACX,iBAAkB;MAC1CE,mBAAmB,EAAEA,mBAAoB;MACzCU,qBAAqB,EAAEX,WAAW,CAACY,CAAE;MACrCC,qBAAqB,EAAEb,WAAW,CAACc;IAAE,CACtC,CAAC,EACDrB,QAAQ;EAAA,CACgB,CAAC;AAEhC,CAAC;AAED,OAAO,MAAMsB,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,OAAO,GAAGjC,UAAU,CAACQ,gBAAgB,CAAC;EAC5C,IAAI,CAACyB,OAAO,EAAE;IACZ,MAAM,IAAIC,KAAK,CACb,sEACF,CAAC;EACH;EACA,OAAOD,OAAO;AAChB,CAAC","ignoreList":[]}
|
|
@@ -7,9 +7,17 @@ export const useInternalTranslateSheet = () => {
|
|
|
7
7
|
const [isIOSTranslateSheetPresented, setIsIOSTranslateSheetPresented] = useState(false);
|
|
8
8
|
const textRef = useRef("");
|
|
9
9
|
const replacementActionRef = useRef(undefined);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const anchorPoint = useRef({
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0
|
|
13
|
+
});
|
|
14
|
+
const presentIOSTranslateSheet = params => {
|
|
15
|
+
textRef.current = params.text;
|
|
16
|
+
replacementActionRef.current = params.replacementAction;
|
|
17
|
+
anchorPoint.current = {
|
|
18
|
+
x: params.gestureEvent?.nativeEvent.pageX || 0,
|
|
19
|
+
y: params.gestureEvent?.nativeEvent.pageY || 0
|
|
20
|
+
};
|
|
13
21
|
setIsIOSTranslateSheetPresented(true);
|
|
14
22
|
};
|
|
15
23
|
const hideTranslateSheet = () => {
|
|
@@ -21,7 +29,8 @@ export const useInternalTranslateSheet = () => {
|
|
|
21
29
|
hideTranslateSheet,
|
|
22
30
|
text: textRef.current,
|
|
23
31
|
isSupported,
|
|
24
|
-
replacementAction: replacementActionRef.current
|
|
32
|
+
replacementAction: replacementActionRef.current,
|
|
33
|
+
anchorPoint: anchorPoint.current
|
|
25
34
|
};
|
|
26
35
|
};
|
|
27
36
|
//# sourceMappingURL=useInternalTranslate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","useState","Platform","isSupported","OS","Number","parseFloat","String","Version","useInternalTranslateSheet","isIOSTranslateSheetPresented","setIsIOSTranslateSheetPresented","textRef","replacementActionRef","undefined","
|
|
1
|
+
{"version":3,"names":["useRef","useState","Platform","isSupported","OS","Number","parseFloat","String","Version","useInternalTranslateSheet","isIOSTranslateSheetPresented","setIsIOSTranslateSheetPresented","textRef","replacementActionRef","undefined","anchorPoint","x","y","presentIOSTranslateSheet","params","current","text","replacementAction","gestureEvent","nativeEvent","pageX","pageY","hideTranslateSheet"],"sourceRoot":"../../../src","sources":["hooks/useInternalTranslate.tsx"],"mappings":";;AAAA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACxC,SAASC,QAAQ,QAAQ,cAAc;AAGvC,MAAMC,WAAW,GACfD,QAAQ,CAACE,EAAE,KAAK,KAAK,IAAIC,MAAM,CAACC,UAAU,CAACC,MAAM,CAACL,QAAQ,CAACM,OAAO,CAAC,CAAC,IAAI,IAAI;AAE9E,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAM,CAACC,4BAA4B,EAAEC,+BAA+B,CAAC,GACnEV,QAAQ,CAAC,KAAK,CAAC;EACjB,MAAMW,OAAO,GAAGZ,MAAM,CAAC,EAAE,CAAC;EAC1B,MAAMa,oBAAoB,GAAGb,MAAM,CAAyBc,SAAS,CAAC;EACtE,MAAMC,WAAW,GAAGf,MAAM,CAA2B;IAAEgB,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC,CAAC;EAEpE,MAAMC,wBAAwB,GAAIC,MAAsC,IAAK;IAC3EP,OAAO,CAACQ,OAAO,GAAGD,MAAM,CAACE,IAAI;IAC7BR,oBAAoB,CAACO,OAAO,GAAGD,MAAM,CAACG,iBAAiB;IACvDP,WAAW,CAACK,OAAO,GAAG;MACpBJ,CAAC,EAAEG,MAAM,CAACI,YAAY,EAAEC,WAAW,CAACC,KAAK,IAAI,CAAC;MAC9CR,CAAC,EAAEE,MAAM,CAACI,YAAY,EAAEC,WAAW,CAACE,KAAK,IAAI;IAC/C,CAAC;IACDf,+BAA+B,CAAC,IAAI,CAAC;EACvC,CAAC;EAED,MAAMgB,kBAAkB,GAAGA,CAAA,KAAM;IAC/BhB,+BAA+B,CAAC,KAAK,CAAC;EACxC,CAAC;EAED,OAAO;IACLD,4BAA4B;IAC5BQ,wBAAwB;IACxBS,kBAAkB;IAClBN,IAAI,EAAET,OAAO,CAACQ,OAAO;IACrBjB,WAAW;IACXmB,iBAAiB,EAAET,oBAAoB,CAACO,OAAO;IAC/CL,WAAW,EAAEA,WAAW,CAACK;EAC3B,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import type { DirectEventHandler } from "react-native/Libraries/Types/CodegenTypes";
|
|
2
|
+
import type { DirectEventHandler, Double } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
3
|
export interface OnReplacementActionEvent {
|
|
4
4
|
text: string;
|
|
5
5
|
}
|
|
@@ -7,6 +7,8 @@ interface IOSTranslateSheetProps extends ViewProps {
|
|
|
7
7
|
text: string;
|
|
8
8
|
isPresented: boolean;
|
|
9
9
|
hasReplacementAction: boolean;
|
|
10
|
+
translateAnchorPointX?: Double;
|
|
11
|
+
translateAnchorPointY?: Double;
|
|
10
12
|
onHide: DirectEventHandler<null>;
|
|
11
13
|
onReplacementAction?: DirectEventHandler<OnReplacementActionEvent>;
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOSTranslateSheetViewNativeComponent.d.ts","sourceRoot":"","sources":["../../src/IOSTranslateSheetViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"IOSTranslateSheetViewNativeComponent.d.ts","sourceRoot":"","sources":["../../src/IOSTranslateSheetViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EACV,kBAAkB,EAClB,MAAM,EACP,MAAM,2CAA2C,CAAC;AAGnD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,sBAAuB,SAAQ,SAAS;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACjC,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;CACpE;;AAED,wBAEE"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
import { type GestureResponderEvent } from "react-native";
|
|
3
|
+
export type PresentIOSTranslateSheetParams = {
|
|
4
|
+
text: string;
|
|
5
|
+
replacementAction?: (text: string) => void;
|
|
6
|
+
gestureEvent?: GestureResponderEvent;
|
|
7
|
+
};
|
|
2
8
|
type TranslateContextType = {
|
|
3
9
|
isSupported: boolean;
|
|
4
|
-
presentIOSTranslateSheet: (
|
|
10
|
+
presentIOSTranslateSheet: (params: PresentIOSTranslateSheetParams) => void;
|
|
5
11
|
};
|
|
6
12
|
export declare const IOSTranslateSheetProvider: ({ children, }: {
|
|
7
13
|
children: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslateContext.d.ts","sourceRoot":"","sources":["../../src/TranslateContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA6B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TranslateContext.d.ts","sourceRoot":"","sources":["../../src/TranslateContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA6B,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,KAAK,qBAAqB,EAG3B,MAAM,cAAc,CAAC;AAMtB,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,WAAW,EAAE,OAAO,CAAC;IACrB,wBAAwB,EAAE,CAAC,MAAM,EAAE,8BAA8B,KAAK,IAAI,CAAC;CAC5E,CAAC;AAIF,eAAO,MAAM,yBAAyB,GAAI,eAEvC;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAqCzB,CAAC;AAEF,eAAO,MAAM,oBAAoB,4BAQhC,CAAC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import type { PresentIOSTranslateSheetParams } from "../TranslateContext";
|
|
1
2
|
export declare const useInternalTranslateSheet: () => {
|
|
2
3
|
isIOSTranslateSheetPresented: boolean;
|
|
3
|
-
presentIOSTranslateSheet: (
|
|
4
|
+
presentIOSTranslateSheet: (params: PresentIOSTranslateSheetParams) => void;
|
|
4
5
|
hideTranslateSheet: () => void;
|
|
5
6
|
text: string;
|
|
6
7
|
isSupported: boolean;
|
|
7
8
|
replacementAction: ((text: string) => void) | undefined;
|
|
9
|
+
anchorPoint: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
8
13
|
};
|
|
9
14
|
//# sourceMappingURL=useInternalTranslate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInternalTranslate.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInternalTranslate.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInternalTranslate.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInternalTranslate.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAK1E,eAAO,MAAM,yBAAyB;;uCAOM,8BAA8B;;;;+BAH7B,MAAM,KAAK,IAAI;;WAC1B,MAAM;WAAK,MAAM;;CAyBlD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ios-translate-sheet",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "SwiftUI Translate Sheet on React Native",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "lib/commonjs/index.js",
|
|
@@ -58,26 +58,26 @@
|
|
|
58
58
|
"registry": "https://registry.npmjs.org/"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@biomejs/biome": "
|
|
62
|
-
"@commitlint/config-conventional": "
|
|
61
|
+
"@biomejs/biome": "1.9.4",
|
|
62
|
+
"@commitlint/config-conventional": "19.8.0",
|
|
63
63
|
"@react-native-community/cli": "15.1.3",
|
|
64
|
-
"@semantic-release/changelog": "
|
|
65
|
-
"@semantic-release/git": "
|
|
66
|
-
"@types/jest": "
|
|
67
|
-
"@types/react": "
|
|
68
|
-
"commitlint": "
|
|
69
|
-
"del-cli": "
|
|
70
|
-
"husky": "
|
|
71
|
-
"jest": "
|
|
72
|
-
"react": "19.
|
|
64
|
+
"@semantic-release/changelog": "6.0.3",
|
|
65
|
+
"@semantic-release/git": "10.0.1",
|
|
66
|
+
"@types/jest": "29.5.14",
|
|
67
|
+
"@types/react": "19.0.10",
|
|
68
|
+
"commitlint": "19.8.0",
|
|
69
|
+
"del-cli": "6.0.0",
|
|
70
|
+
"husky": "9.1.7",
|
|
71
|
+
"jest": "29.7.0",
|
|
72
|
+
"react": "19.1.0",
|
|
73
73
|
"react-native": "0.78.2",
|
|
74
|
-
"react-native-builder-bob": "
|
|
75
|
-
"semantic-release": "
|
|
76
|
-
"turbo": "
|
|
77
|
-
"typescript": "
|
|
74
|
+
"react-native-builder-bob": "0.40.3",
|
|
75
|
+
"semantic-release": "24.2.3",
|
|
76
|
+
"turbo": "2.5.0",
|
|
77
|
+
"typescript": "5.8.3"
|
|
78
78
|
},
|
|
79
79
|
"resolutions": {
|
|
80
|
-
"@types/react": "
|
|
80
|
+
"@types/react": "19.1.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"react": "*",
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DirectEventHandler,
|
|
4
|
+
Double,
|
|
5
|
+
} from "react-native/Libraries/Types/CodegenTypes";
|
|
3
6
|
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
4
7
|
|
|
5
8
|
export interface OnReplacementActionEvent {
|
|
@@ -10,6 +13,8 @@ interface IOSTranslateSheetProps extends ViewProps {
|
|
|
10
13
|
text: string;
|
|
11
14
|
isPresented: boolean;
|
|
12
15
|
hasReplacementAction: boolean;
|
|
16
|
+
translateAnchorPointX?: Double;
|
|
17
|
+
translateAnchorPointY?: Double;
|
|
13
18
|
onHide: DirectEventHandler<null>;
|
|
14
19
|
onReplacementAction?: DirectEventHandler<OnReplacementActionEvent>;
|
|
15
20
|
}
|
package/src/TranslateContext.tsx
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { type ReactNode, createContext, useContext } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type GestureResponderEvent,
|
|
4
|
+
type NativeSyntheticEvent,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
} from "react-native";
|
|
3
7
|
import IOSTranslateSheet, {
|
|
4
8
|
type OnReplacementActionEvent,
|
|
5
9
|
} from "./IOSTranslateSheetViewNativeComponent";
|
|
6
10
|
import { useInternalTranslateSheet } from "./hooks/useInternalTranslate";
|
|
7
11
|
|
|
12
|
+
export type PresentIOSTranslateSheetParams = {
|
|
13
|
+
text: string;
|
|
14
|
+
replacementAction?: (text: string) => void;
|
|
15
|
+
gestureEvent?: GestureResponderEvent;
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
type TranslateContextType = {
|
|
9
19
|
isSupported: boolean;
|
|
10
|
-
presentIOSTranslateSheet: (
|
|
11
|
-
text: string,
|
|
12
|
-
replacementAction?: (text: string) => void,
|
|
13
|
-
) => void;
|
|
20
|
+
presentIOSTranslateSheet: (params: PresentIOSTranslateSheetParams) => void;
|
|
14
21
|
};
|
|
15
22
|
|
|
16
23
|
const TranslateContext = createContext<TranslateContextType | null>(null);
|
|
@@ -25,6 +32,7 @@ export const IOSTranslateSheetProvider = ({
|
|
|
25
32
|
hideTranslateSheet,
|
|
26
33
|
isSupported,
|
|
27
34
|
replacementAction,
|
|
35
|
+
anchorPoint,
|
|
28
36
|
} = useInternalTranslateSheet();
|
|
29
37
|
|
|
30
38
|
const onReplacementAction = (
|
|
@@ -47,6 +55,8 @@ export const IOSTranslateSheetProvider = ({
|
|
|
47
55
|
style={StyleSheet.absoluteFillObject}
|
|
48
56
|
hasReplacementAction={!!replacementAction}
|
|
49
57
|
onReplacementAction={onReplacementAction}
|
|
58
|
+
translateAnchorPointX={anchorPoint.x}
|
|
59
|
+
translateAnchorPointY={anchorPoint.y}
|
|
50
60
|
/>
|
|
51
61
|
{children}
|
|
52
62
|
</TranslateContext.Provider>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRef, useState } from "react";
|
|
2
2
|
import { Platform } from "react-native";
|
|
3
|
+
import type { PresentIOSTranslateSheetParams } from "../TranslateContext";
|
|
3
4
|
|
|
4
5
|
const isSupported =
|
|
5
6
|
Platform.OS === "ios" && Number.parseFloat(String(Platform.Version)) >= 17.4;
|
|
@@ -9,13 +10,15 @@ export const useInternalTranslateSheet = () => {
|
|
|
9
10
|
useState(false);
|
|
10
11
|
const textRef = useRef("");
|
|
11
12
|
const replacementActionRef = useRef<(text: string) => void>(undefined);
|
|
13
|
+
const anchorPoint = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
|
12
14
|
|
|
13
|
-
const presentIOSTranslateSheet = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const presentIOSTranslateSheet = (params: PresentIOSTranslateSheetParams) => {
|
|
16
|
+
textRef.current = params.text;
|
|
17
|
+
replacementActionRef.current = params.replacementAction;
|
|
18
|
+
anchorPoint.current = {
|
|
19
|
+
x: params.gestureEvent?.nativeEvent.pageX || 0,
|
|
20
|
+
y: params.gestureEvent?.nativeEvent.pageY || 0,
|
|
21
|
+
};
|
|
19
22
|
setIsIOSTranslateSheetPresented(true);
|
|
20
23
|
};
|
|
21
24
|
|
|
@@ -30,5 +33,6 @@ export const useInternalTranslateSheet = () => {
|
|
|
30
33
|
text: textRef.current,
|
|
31
34
|
isSupported,
|
|
32
35
|
replacementAction: replacementActionRef.current,
|
|
36
|
+
anchorPoint: anchorPoint.current,
|
|
33
37
|
};
|
|
34
38
|
};
|