@dl2app/react-native 0.0.0-stage → 0.1.1
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 +313 -2
- package/android/build.gradle +24 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/app/dl2/reactnative/DL2Module.kt +134 -0
- package/app.plugin.js +3 -0
- package/build/plugin/src/withDL2.d.ts +62 -0
- package/build/plugin/src/withDL2.js +174 -0
- package/build/src/PasteButton.d.ts +14 -0
- package/build/src/PasteButton.js +44 -0
- package/build/src/core.d.ts +32 -0
- package/build/src/core.js +937 -0
- package/build/src/index.d.ts +22 -0
- package/build/src/index.js +33 -0
- package/build/src/types.d.ts +130 -0
- package/build/src/types.js +2 -0
- package/expo-module.config.json +5 -0
- package/ios/DL2Module.swift +59 -0
- package/ios/DL2PasteButtonView.swift +41 -0
- package/ios/DL2ReactNative.podspec +22 -0
- package/ios/PrivacyInfo.xcprivacy +76 -0
- package/package.json +35 -4
- package/plugin/src/withDL2.ts +202 -0
- package/src/PasteButton.ts +48 -0
- package/src/core.ts +922 -0
- package/src/index.ts +41 -0
- package/src/types.ts +127 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElement, type ComponentType, type ReactElement } from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import { requireNativeViewManager } from "expo-modules-core";
|
|
4
|
+
|
|
5
|
+
export type DL2PasteButtonProps = {
|
|
6
|
+
/** Called with the pasted text after the user taps the button. */
|
|
7
|
+
onPaste: (text: string) => void;
|
|
8
|
+
/** Size the button here; the system draws its label and icon. */
|
|
9
|
+
style?: unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type NativeProps = { style?: unknown; onPaste: (e: { nativeEvent: { text?: string } }) => void };
|
|
13
|
+
|
|
14
|
+
let NativeView: ComponentType<NativeProps> | null | undefined;
|
|
15
|
+
|
|
16
|
+
function nativeView(): ComponentType<NativeProps> | null {
|
|
17
|
+
if (NativeView === undefined) {
|
|
18
|
+
try {
|
|
19
|
+
NativeView = requireNativeViewManager<NativeProps>("DL2");
|
|
20
|
+
} catch {
|
|
21
|
+
NativeView = null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return NativeView || null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The system paste button (UIPasteControl, iOS 16+). iOS hands over the clipboard only when the
|
|
29
|
+
* user taps it, and shows no "pasted from" banner. Renders nothing on Android and on older iOS.
|
|
30
|
+
*
|
|
31
|
+
* <DL2PasteButton style={{ width: 160, height: 44 }} onPaste={(text) => DL2.matchClipboard(text)} />
|
|
32
|
+
*/
|
|
33
|
+
export function DL2PasteButton(props: DL2PasteButtonProps): ReactElement | null {
|
|
34
|
+
if (Platform.OS !== "ios" || parseInt(String(Platform.Version), 10) < 16) return null;
|
|
35
|
+
const View = nativeView();
|
|
36
|
+
if (!View) return null;
|
|
37
|
+
return createElement(View, {
|
|
38
|
+
style: props.style || { width: 160, height: 44 },
|
|
39
|
+
onPaste: (e) => {
|
|
40
|
+
try {
|
|
41
|
+
const text = e && e.nativeEvent ? e.nativeEvent.text : undefined;
|
|
42
|
+
if (typeof text === "string" && text) props.onPaste(text);
|
|
43
|
+
} catch {
|
|
44
|
+
/* never let a handler error reach the native event dispatcher */
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|