dreaction-react-native 1.3.4 → 1.4.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.
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  interface ConfigDialogProps {
3
3
  visible: boolean;
4
- onConfirm: (value: string) => void;
4
+ onConfirm: (host: string) => void;
5
5
  onCancel: () => void;
6
6
  }
7
7
  export declare const ConfigDialog: React.FC<ConfigDialogProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigDialog.d.ts","sourceRoot":"","sources":["../../src/components/ConfigDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAIxC,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AACD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAiCnD,CAAC"}
1
+ {"version":3,"file":"ConfigDialog.d.ts","sourceRoot":"","sources":["../../src/components/ConfigDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAenD,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AACD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAqDnD,CAAC"}
@@ -38,13 +38,29 @@ const jsx_runtime_1 = require("react/jsx-runtime");
38
38
  const react_1 = __importStar(require("react"));
39
39
  const react_native_1 = require("react-native");
40
40
  const getHost_1 = require("../helpers/getHost");
41
+ const dreaction_1 = require("../dreaction");
42
+ const parseURL_1 = require("../helpers/parseURL");
43
+ const LOCAL_CACHE_HOST_NAME = '__dreaction-react-native-host';
41
44
  exports.ConfigDialog = react_1.default.memo((props) => {
42
45
  const { visible, onConfirm, onCancel } = props;
43
- const [inputValue, setInputValue] = (0, react_1.useState)((0, getHost_1.getHost)());
46
+ const defaultValue = (0, getHost_1.getHost)();
47
+ const [inputValue, setInputValue] = (0, react_1.useState)(defaultValue);
48
+ const selectTextOnFocus = inputValue === defaultValue;
49
+ (0, react_1.useEffect)(() => {
50
+ dreaction_1.dreaction.asyncStorageHandler
51
+ ?.getItem(LOCAL_CACHE_HOST_NAME)
52
+ .then((host) => {
53
+ if (host) {
54
+ setInputValue(host);
55
+ }
56
+ });
57
+ }, []);
44
58
  const handleConfirm = () => {
45
- onConfirm(inputValue);
59
+ const host = (0, parseURL_1.getHostFromUrl)(inputValue);
60
+ dreaction_1.dreaction.asyncStorageHandler?.setItem(LOCAL_CACHE_HOST_NAME, host);
61
+ onConfirm(host);
46
62
  };
47
- return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { animationType: "fade", transparent: true, visible: visible, onRequestClose: () => onCancel(), children: (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.modalOverlay, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.modalContent, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.title, children: "DReaction Desktop Application Url" }), (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { style: styles.input, value: inputValue, keyboardType: "url", onChangeText: setInputValue, placeholder: (0, getHost_1.getHost)() }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.buttonContainer, children: [(0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "Cancel", onPress: onCancel }), (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "Confirm", onPress: handleConfirm })] })] }) }) }));
63
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { animationType: "fade", transparent: true, visible: visible, onRequestClose: () => onCancel(), children: (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.modalOverlay, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.modalContent, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.title, children: "DReaction Desktop Application Url" }), (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { style: styles.input, selectTextOnFocus: selectTextOnFocus, value: inputValue, keyboardType: "url", onChangeText: setInputValue, placeholder: (0, getHost_1.getHost)() }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.buttonContainer, children: [(0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { style: styles.buttonView, onPress: onCancel, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.buttonText, children: "Cancel" }) }), (0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { style: styles.buttonView, onPress: handleConfirm, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.buttonText, children: "Confirm" }) })] })] }) }) }));
48
64
  });
49
65
  exports.ConfigDialog.displayName = 'ConfigDialog';
50
66
  const styles = react_native_1.StyleSheet.create({
@@ -73,6 +89,7 @@ const styles = react_native_1.StyleSheet.create({
73
89
  borderWidth: 1,
74
90
  borderColor: '#ccc',
75
91
  borderRadius: 5,
92
+ color: 'black',
76
93
  padding: 10,
77
94
  marginBottom: 20,
78
95
  },
@@ -80,4 +97,11 @@ const styles = react_native_1.StyleSheet.create({
80
97
  flexDirection: 'row',
81
98
  justifyContent: 'space-around',
82
99
  },
100
+ buttonView: {
101
+ flexDirection: 'row',
102
+ justifyContent: 'space-around',
103
+ },
104
+ buttonText: {
105
+ color: '#2563eb',
106
+ },
83
107
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DraggableBall.d.ts","sourceRoot":"","sources":["../../src/components/DraggableBall.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAsB3D,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA4GhC,CAAC"}
1
+ {"version":3,"file":"DraggableBall.d.ts","sourceRoot":"","sources":["../../src/components/DraggableBall.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAqB3D,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA0GhC,CAAC"}
@@ -39,7 +39,6 @@ const react_1 = __importStar(require("react"));
39
39
  const react_native_1 = require("react-native");
40
40
  const ConfigDialog_1 = require("./ConfigDialog");
41
41
  const dreaction_1 = require("../dreaction");
42
- const parseURL_1 = require("../helpers/parseURL");
43
42
  const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = react_native_1.Dimensions.get('window');
44
43
  const BALL_SIZE = 60;
45
44
  const CLICK_THRESHOLD = 5;
@@ -61,9 +60,8 @@ exports.DraggableBall = react_1.default.memo(() => {
61
60
  clearInterval(timer);
62
61
  };
63
62
  }, []);
64
- const handleClick = (value) => {
63
+ const handleClick = (host) => {
65
64
  try {
66
- const host = (0, parseURL_1.getHostFromUrl)(value);
67
65
  dreaction_1.dreaction
68
66
  .configure({
69
67
  host,
@@ -1 +1 @@
1
- {"version":3,"file":"dreaction.d.ts","sourceRoot":"","sources":["../src/dreaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EAExB,SAAS,EACT,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAGpF,OAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAA0B,EACxB,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAKtD,YAAY,EAAE,aAAa,EAAE,CAAC;AAM9B,eAAO,MAAM,sBAAsB,OAOO,CAAC;AAE3C,MAAM,WAAW,qBAAqB;IACpC,MA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C,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;QAC1C,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;KAC9C,CAAC;CACH;AAkFD,eAAO,MAAM,SAAS,sBAA+C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"asyncStorage.d.ts","sourceRoot":"","sources":["../../src/plugins/asyncStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,uBAAuB,CAAC;AAGnE,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAMD,QAAA,MAAM,YAAY,aACL,mBAAmB,iBAAiB,aAAa;;;;;CA+M3D,CAAC;AAEJ,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"asyncStorage.d.ts","sourceRoot":"","sources":["../../src/plugins/asyncStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,uBAAuB,CAAC;AAEnE,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAMD,QAAA,MAAM,YAAY,aACL,mBAAmB,iBAAiB,aAAa;;;;;CA+M3D,CAAC;AAEJ,eAAe,YAAY,CAAC"}
@@ -16,7 +16,7 @@ const asyncStorage = (options) => (dreaction) => {
16
16
  let swizzMultiMerge;
17
17
  let isSwizzled = false;
18
18
  const sendToDReaction = (action, data) => {
19
- dreaction.send('asyncStorage.mutation', { action, data });
19
+ dreaction.send('asyncStorage.mutation', { action: action, data });
20
20
  };
21
21
  const setItem = async (key, value, callback) => {
22
22
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dreaction-react-native",
3
- "version": "1.3.4",
3
+ "version": "1.4.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "lib/index.js",
@@ -19,9 +19,13 @@
19
19
  "dreaction-protocol": "1.0.1"
20
20
  },
21
21
  "devDependencies": {
22
+ "@react-native-async-storage/async-storage": "^2.1.0",
22
23
  "@types/react-native": "^0.73.0",
23
24
  "typescript": "^5.4.5"
24
25
  },
26
+ "peerDependencies": {
27
+ "@react-native-async-storage/async-storage": "*"
28
+ },
25
29
  "scripts": {
26
30
  "dev": "tsc --watch",
27
31
  "build": "tsc",
@@ -1,18 +1,44 @@
1
- import React, { useState } from 'react';
2
- import { View, Text, TextInput, Button, Modal, StyleSheet } from 'react-native';
1
+ import React, { useState, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TextInput,
6
+ Modal,
7
+ StyleSheet,
8
+ TouchableOpacity,
9
+ } from 'react-native';
3
10
  import { getHost } from '../helpers/getHost';
11
+ import { dreaction } from '../dreaction';
12
+ import { getHostFromUrl } from '../helpers/parseURL';
13
+
14
+ const LOCAL_CACHE_HOST_NAME = '__dreaction-react-native-host';
4
15
 
5
16
  interface ConfigDialogProps {
6
17
  visible: boolean;
7
- onConfirm: (value: string) => void;
18
+ onConfirm: (host: string) => void;
8
19
  onCancel: () => void;
9
20
  }
10
21
  export const ConfigDialog: React.FC<ConfigDialogProps> = React.memo((props) => {
11
22
  const { visible, onConfirm, onCancel } = props;
12
- const [inputValue, setInputValue] = useState(getHost());
23
+ const defaultValue = getHost();
24
+ const [inputValue, setInputValue] = useState(defaultValue);
25
+
26
+ const selectTextOnFocus = inputValue === defaultValue;
27
+
28
+ useEffect(() => {
29
+ dreaction.asyncStorageHandler
30
+ ?.getItem(LOCAL_CACHE_HOST_NAME)
31
+ .then((host) => {
32
+ if (host) {
33
+ setInputValue(host);
34
+ }
35
+ });
36
+ }, []);
13
37
 
14
38
  const handleConfirm = () => {
15
- onConfirm(inputValue);
39
+ const host = getHostFromUrl(inputValue);
40
+ dreaction.asyncStorageHandler?.setItem(LOCAL_CACHE_HOST_NAME, host);
41
+ onConfirm(host);
16
42
  };
17
43
 
18
44
  return (
@@ -27,14 +53,19 @@ export const ConfigDialog: React.FC<ConfigDialogProps> = React.memo((props) => {
27
53
  <Text style={styles.title}>DReaction Desktop Application Url</Text>
28
54
  <TextInput
29
55
  style={styles.input}
56
+ selectTextOnFocus={selectTextOnFocus}
30
57
  value={inputValue}
31
58
  keyboardType="url"
32
59
  onChangeText={setInputValue}
33
60
  placeholder={getHost()}
34
61
  />
35
62
  <View style={styles.buttonContainer}>
36
- <Button title="Cancel" onPress={onCancel} />
37
- <Button title="Confirm" onPress={handleConfirm} />
63
+ <TouchableOpacity style={styles.buttonView} onPress={onCancel}>
64
+ <Text style={styles.buttonText}>Cancel</Text>
65
+ </TouchableOpacity>
66
+ <TouchableOpacity style={styles.buttonView} onPress={handleConfirm}>
67
+ <Text style={styles.buttonText}>Confirm</Text>
68
+ </TouchableOpacity>
38
69
  </View>
39
70
  </View>
40
71
  </View>
@@ -69,6 +100,7 @@ const styles = StyleSheet.create({
69
100
  borderWidth: 1,
70
101
  borderColor: '#ccc',
71
102
  borderRadius: 5,
103
+ color: 'black',
72
104
  padding: 10,
73
105
  marginBottom: 20,
74
106
  },
@@ -76,4 +108,11 @@ const styles = StyleSheet.create({
76
108
  flexDirection: 'row',
77
109
  justifyContent: 'space-around',
78
110
  },
111
+ buttonView: {
112
+ flexDirection: 'row',
113
+ justifyContent: 'space-around',
114
+ },
115
+ buttonText: {
116
+ color: '#2563eb',
117
+ },
79
118
  });
@@ -9,7 +9,6 @@ import {
9
9
  } from 'react-native';
10
10
  import { ConfigDialog } from './ConfigDialog';
11
11
  import { dreaction } from '../dreaction';
12
- import { getHostFromUrl } from '../helpers/parseURL';
13
12
 
14
13
  const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
15
14
  const BALL_SIZE = 60;
@@ -37,10 +36,8 @@ export const DraggableBall: React.FC = React.memo(() => {
37
36
  };
38
37
  }, []);
39
38
 
40
- const handleClick = (value: string) => {
39
+ const handleClick = (host: string) => {
41
40
  try {
42
- const host = getHostFromUrl(value);
43
-
44
41
  dreaction
45
42
  .configure({
46
43
  host,
package/src/dreaction.ts CHANGED
@@ -7,7 +7,6 @@ import type {
7
7
  DReaction,
8
8
  DReactionCore,
9
9
  } from 'dreaction-client-core';
10
- // @ts-ignore
11
10
  import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
12
11
  import getReactNativeVersion from './helpers/getReactNativeVersion';
13
12
  import getReactNativeDimensions from './helpers/getReactNativeDimensions';
@@ -1,5 +1,4 @@
1
1
  import type { DReactionCore, Plugin } from 'dreaction-client-core';
2
- // @ts-ignore
3
2
  import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
4
3
  export interface AsyncStorageOptions {
5
4
  ignore?: string[];
@@ -25,7 +24,7 @@ const asyncStorage =
25
24
  let isSwizzled = false;
26
25
 
27
26
  const sendToDReaction = (action: string, data?: any) => {
28
- dreaction.send('asyncStorage.mutation', { action, data });
27
+ dreaction.send('asyncStorage.mutation', { action: action as any, data });
29
28
  };
30
29
 
31
30
  const setItem: AsyncStorageStatic['setItem'] = async (