esoftplay 0.0.141-u → 0.0.141-w

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,5 +1,8 @@
1
1
  // withHooks
2
+ import { LibNavigationRoutes } from 'esoftplay';
3
+ import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
2
4
  import { LibObject } from 'esoftplay/cache/lib/object/import';
5
+ import { LibUtils } from 'esoftplay/cache/lib/utils/import';
3
6
  import { EspRouterInterface } from 'esoftplay/cache/routers';
4
7
  import esp from 'esoftplay/esp';
5
8
  import useGlobalState from 'esoftplay/global';
@@ -14,31 +17,7 @@ export interface RNTypes extends EspRouterInterface {
14
17
  // "TextInput": typeof TextInput,
15
18
  }
16
19
 
17
- const form = useGlobalState({})
18
-
19
- const action: any = {
20
- "navigate": (args: any[]) => esp.mod("lib/navigation").navigate(args[0], args[1]),
21
- "replace": (args: any[]) => esp.mod("lib/navigation").replace(args[0], args[1]),
22
- "back": (args: any[]) => esp.mod("lib/navigation").back(),
23
- "copy": (args: any[]) => {
24
- esp.mod("lib/utils").copyToClipboard(JSON.stringify(args))
25
- esp.modProp("lib/toast").show(args + " copied!")
26
- },
27
- "curl": (args: any[]) => {
28
- let post = args?.[1]
29
- try {
30
- post = JSON.parse(args?.[1])
31
- } catch (error) {
32
- post = args?.[1]
33
- }
34
- post = Object.assign({}, post, form.get())
35
- new (esp.mod('lib/curl'))(args[0], post, (res, msg) => {
36
- esp.modProp("lib/toast").show(msg)
37
- }, (err) => {
38
- esp.modProp("lib/toast").show(err.message)
39
- }, 1)
40
- }
41
- }
20
+ const formState = useGlobalState({})
42
21
 
43
22
  function buildUIFromJSON(json: any): ReactElement {
44
23
  const { component, props } = json;
@@ -80,14 +59,14 @@ function buildUIFromJSON(json: any): ReactElement {
80
59
  const [type, postkey] = cleanForm.split('.')
81
60
  if (type == 'input') {
82
61
  _props[key] = (input: string) => {
83
- form.set(LibObject.set(form.get(), input)(postkey))
62
+ formState.set(LibObject.set(formState.get(), input)(postkey))
84
63
  }
85
64
  }
86
65
  if (type == 'select') {
87
66
  console.log(type, postkey, key)
88
67
  const [_key, _value] = postkey.split(":")
89
68
  _props[key] = () => {
90
- form.set(LibObject.set(form.get(), _value)(_key))
69
+ formState.set(LibObject.set(formState.get(), _value)(_key))
91
70
  }
92
71
  }
93
72
  } else {
@@ -109,6 +88,60 @@ export default function m({ schema }: { schema: any }): ReactElement {
109
88
  return buildUIFromJSON(schema)
110
89
  }
111
90
 
91
+ const action: any = {
92
+ "navigate": (args: any[]) => esp.mod("lib/navigation").navigate(args[0], args[1]),
93
+ "replace": (args: any[]) => esp.mod("lib/navigation").replace(args[0], args[1]),
94
+ "back": (args: any[]) => esp.mod("lib/navigation").back(),
95
+ "copy": (args: any[]) => {
96
+ esp.mod("lib/utils").copyToClipboard(JSON.stringify(args))
97
+ esp.modProp("lib/toast").show(args + " copied!")
98
+ },
99
+ "curl": (args: any[]) => {
100
+ esp.mod("lib/progress").show("Please Wait..")
101
+ let post = args?.[1]
102
+ try {
103
+ post = JSON.parse(args?.[1])
104
+ } catch (error) {
105
+ post = args?.[1]
106
+ }
107
+ post = Object.assign({}, post, formState.get())
108
+ new (esp.mod('lib/curl'))(args[0], post, (res, msg) => {
109
+ esp.modProp("lib/toast").show(msg)
110
+ esp.mod("lib/progress").hide()
111
+ }, (err) => {
112
+ esp.modProp("lib/toast").show(err.message)
113
+ esp.mod("lib/progress").hide()
114
+ })
115
+ }
116
+ }
117
+
118
+ export const forms = {
119
+ select: (postKey: string, value: string) => `#form.select.${postKey}:${value}`,
120
+ input: (postKey: string) => `#form.input.${postKey}`,
121
+ }
122
+ export const actions = {
123
+ navigate: (module: LibNavigationRoutes, params: any) => {
124
+ LibNavigation.navigate(module, params)
125
+ },
126
+ replace: (module: LibNavigationRoutes, params: any) => {
127
+ LibNavigation.replace(module, params)
128
+ },
129
+ back: () => {
130
+ LibNavigation.back()
131
+ },
132
+ copy: (args: string) => {
133
+ LibUtils.copyToClipboard(args)
134
+ esp.modProp("lib/toast").show(args + " copied!")
135
+ },
136
+ curl: (uri: string, post?: any) => {
137
+ new (esp.mod('lib/curl'))(uri, post, (res, msg) => {
138
+ esp.modProp("lib/toast").show(msg)
139
+ }, (err) => {
140
+ esp.modProp("lib/toast").show(err.message)
141
+ }, 1)
142
+ }
143
+ }
144
+
112
145
  export function build<T extends keyof RNTypes>(cmpn: T, props: React.ComponentProps<RNTypes[T]>): any {
113
146
  let obj: any = {};
114
147
  obj.component = cmpn;
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { LibStyle } from 'esoftplay/cache/lib/style/import';
5
5
  import useGlobalState from 'esoftplay/global';
6
- import React, { useEffect } from 'react';
6
+ import React, { useEffect, useRef } from 'react';
7
7
  import { Text, View } from 'react-native';
8
8
  import Animated, { interpolate, useAnimatedProps, useSharedValue, withTiming } from 'react-native-reanimated';
9
9
 
@@ -16,7 +16,7 @@ const initState = {
16
16
  timeout: 3000
17
17
  }
18
18
 
19
- const state = useGlobalState<any>(initState)
19
+ const state = useGlobalState(initState)
20
20
 
21
21
  let _timeout: any = undefined
22
22
 
@@ -34,12 +34,13 @@ export function show(message: string, timeout?: number): void {
34
34
  _timeout = undefined
35
35
  }
36
36
  _timeout = setTimeout(() => {
37
- hide()
38
37
  clearTimeout(_timeout)
38
+ hide()
39
39
  }, timeout || initState.timeout);
40
40
  }
41
41
 
42
42
  export default function m(props: LibToastProps): any {
43
+ const isFirstInit = useRef(true)
43
44
  const [data] = state.useState()
44
45
  const anim = useSharedValue(0)
45
46
 
@@ -51,11 +52,17 @@ export default function m(props: LibToastProps): any {
51
52
  }))
52
53
 
53
54
  useEffect(() => {
54
- anim.value = withTiming(data?.message ? 1 : 0, { duration: 500 })
55
+ if (!isFirstInit.current && data.message == undefined) {
56
+ anim.value = 1
57
+ }
58
+ if (isFirstInit.current) {
59
+ isFirstInit.current = false
60
+ }
61
+ anim.value = withTiming(data.message != undefined ? 1 : 0, { duration: 500 })
55
62
  }, [data])
56
63
 
57
64
  return (
58
- <Animated.View pointerEvents={'none'} style={[{ flex: 1, position: 'absolute', justifyContent: 'center', alignContent: 'center', alignItems: 'center', top: LibStyle.STATUSBAR_HEIGHT + 20, left: 0, right: 0, }, style, LibStyle.elevation(2)]} >
65
+ <Animated.View pointerEvents={'none'} style={[{ flex: 1, position: 'absolute', justifyContent: 'center', alignContent: 'center', alignItems: 'center', top: LibStyle.STATUSBAR_HEIGHT + 20, opacity: 0, left: 0, right: 0, }, style, LibStyle.elevation(2)]} >
59
66
  <View style={{ maxWidth: Math.min(500, LibStyle.width - 30), minWidth: Math.min(500, LibStyle.width - 30), marginHorizontal: 15, marginVertical: 4, borderRadius: 4, borderWidth: 1, borderColor: '#505050', backgroundColor: '#323232', paddingVertical: 13, paddingHorizontal: 16, }} >
60
67
  <Text style={{ fontSize: 14, textAlign: "center", color: 'white' }} >{String(data?.message || '')}</Text>
61
68
  </View>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.141-u",
3
+ "version": "0.0.141-w",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",