esoftplay 0.0.124-s → 0.0.124-u

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.
@@ -2,25 +2,24 @@
2
2
 
3
3
  import { InteractionManager } from 'react-native'
4
4
 
5
- export default (() => {
6
- let updater = undefined
7
- return {
8
- set(callback: () => void, duration?: number): void {
9
- if (updater != undefined) {
10
- clearInterval(updater)
11
- updater = undefined
12
- }
13
- updater = setInterval(() => {
14
- InteractionManager.runAfterInteractions(() => {
15
- callback()
16
- });
17
- }, duration || 6000)
18
- },
19
- clear(): void {
20
- if (updater != undefined) {
21
- clearInterval(updater)
22
- updater = undefined
23
- }
5
+ let updater: any
6
+ export default class m {
7
+ static set(callback: () => void, duration?: number): void {
8
+ if (updater != undefined) {
9
+ clearInterval(updater)
10
+ updater = undefined
24
11
  }
12
+ updater = setInterval(() => {
13
+ InteractionManager.runAfterInteractions(() => {
14
+ callback()
15
+ });
16
+ }, duration || 6000)
25
17
  }
26
- })()
18
+
19
+ static clear(): void {
20
+ if (updater != undefined) {
21
+ clearInterval(updater)
22
+ updater = undefined
23
+ }
24
+ }
25
+ }
@@ -1,15 +1,7 @@
1
1
  // withHooks
2
2
  // noPage
3
- import { esp, useSafeState } from 'esoftplay';
4
- import { LibStyle } from 'esoftplay/cache/lib/style/import';
5
- import { LibWorkloop } from 'esoftplay/cache/lib/workloop/import';
6
- import useGlobalState from 'esoftplay/global';
7
- import Worker from 'esoftplay/libs/worker';
8
- import * as FileSystem from 'expo-file-system';
9
- import React, { useLayoutEffect } from 'react';
10
- import { PixelRatio, Platform, View } from 'react-native';
3
+ import React from 'react';
11
4
  import FastImage from 'react-native-fast-image';
12
- const sh = require("shorthash")
13
5
 
14
6
  export interface LibPictureSource {
15
7
  uri: string
@@ -22,87 +14,7 @@ export interface LibPictureProps {
22
14
  onError?: () => void,
23
15
  }
24
16
 
25
- const CACHE_DIR = `${FileSystem.cacheDirectory}lib-picture-cache/`;
26
-
27
- (() => {
28
- try {
29
- FileSystem.makeDirectoryAsync(CACHE_DIR).then().catch(e => { });
30
- } catch (e) {
31
- // do nothing
32
- }
33
- })()
34
-
35
- const state = useGlobalState({}, { persistKey: 'lib_picture_paths', inFile: true })
36
- const getCacheEntry = async (uri: string, toSize: number): Promise<{ exists: boolean; path: string }> => {
37
- const path = `${sh.unique(uri)}-${toSize}`;
38
- let info = state.get(path);
39
- if (!info) {
40
- info = await (await FileSystem.getInfoAsync(`${CACHE_DIR}${path}.png`)).exists
41
- }
42
- return { exists: !!info, path: `${CACHE_DIR}${path}.png` };
43
- };
44
-
45
- const fetchPicture = Worker.registerJobAsync('lib_picture_fetch', (url: string, toSize: number) => {
46
- 'show source';
47
- return new Promise((resolve, reject) => {
48
- 'show source';
49
- fetch(url, { mode: 'cors' })
50
- .then(response => response.blob())
51
- .then(blob => {
52
- let reader = new FileReader();
53
- reader.onload = function () {
54
- let img = document.createElement('img');
55
- img.onload = function () {
56
- let wantedMaxSize = toSize
57
- let rawheight = img.height
58
- let rawwidth = img.width
59
- let wantedheight = 0
60
- let wantedwidth = 0
61
- let ratio = rawwidth / rawheight
62
- if (Math.max(rawheight, rawwidth) > wantedMaxSize) {
63
- if (rawheight > rawwidth) {
64
- wantedwidth = wantedMaxSize * ratio;
65
- wantedheight = wantedMaxSize;
66
- } else {
67
- wantedwidth = wantedMaxSize;
68
- wantedheight = wantedMaxSize / ratio;
69
- }
70
- } else {
71
- wantedwidth = rawwidth
72
- wantedheight = rawheight
73
- }
74
- let canvas = document.createElement('canvas');
75
- let ctx = canvas.getContext('2d');
76
- canvas.width = wantedwidth;
77
- canvas.height = wantedheight;
78
- //@ts-ignore
79
- ctx.drawImage(this, 0, 0, wantedwidth, wantedheight);
80
- let x = canvas.toDataURL();
81
- resolve(x.replace("data:image/png;base64,", ""))
82
- }
83
- img.src = String(reader.result)
84
- };
85
- reader.readAsDataURL(blob);
86
- });
87
- })
88
- })
89
-
90
- function savePicture(b_uri: string, toSize: string, path: string, uri: string) {
91
- FileSystem.writeAsStringAsync(path, uri, { encoding: "base64" })
92
- .then(() => {
93
- const _path = `${sh.unique(b_uri)}-${toSize}`;
94
- let dt = state.get()
95
- dt[_path] = 1
96
- state.set(dt)
97
- })
98
- }
99
-
100
17
  export default function m(props: LibPictureProps): any {
101
- const [uri, setUri] = useSafeState('')
102
- let b_uri = props?.source?.uri?.replace?.('://api.', '://')
103
- b_uri = b_uri?.replace?.('://data.', '://')
104
- let { width, height } = props.style
105
- const valid = b_uri?.includes?.(esp.config('domain'))
106
18
 
107
19
  let resizeMode
108
20
  if (props?.style?.resizeMode == 'cover')
@@ -116,54 +28,5 @@ export default function m(props: LibPictureProps): any {
116
28
  else
117
29
  resizeMode = FastImage.resizeMode.cover
118
30
 
119
- if (!width || !height) {
120
- if (width) {
121
- height = width
122
- } else {
123
- width = height
124
- }
125
- console.warn("Width and Height is Required");
126
- }
127
-
128
- useLayoutEffect(() => {
129
- if (!valid || (Platform.OS == 'android' && Platform.Version <= 22)) {
130
- return
131
- }
132
- if (b_uri) {
133
- let toSize = Math.max(width, height)
134
- toSize = isNaN(toSize) ? LibStyle.width * 0.5 : toSize
135
- getCacheEntry(b_uri, toSize).then(({ path, exists }) => {
136
- if (exists) {
137
- setUri(path)
138
- } else {
139
- fetchPicture([b_uri, PixelRatio.getPixelSizeForLayoutSize(toSize)], (uri) => {
140
- setUri("data:image/png;base64," + uri)
141
- if (!props.noCache)
142
- LibWorkloop.execNextTix(savePicture, [b_uri, toSize, path, uri, { encoding: "base64" }])
143
- })
144
- }
145
- })
146
- }
147
- }, [props?.source?.uri])
148
-
149
- if (!valid || (Platform.Version <= 22 && Platform.OS == 'android')) {
150
- if (typeof props.source != 'number' && !b_uri) {
151
- return <View style={props.style} />
152
- }
153
- return <FastImage {...props} resizeMode={resizeMode} />
154
- }
155
-
156
- if (!valid || (!props.source.hasOwnProperty("uri"))) {
157
- return <FastImage {...props} resizeMode={resizeMode} />
158
- }
159
-
160
- if (uri == '') {
161
- return (
162
- <View style={[{ backgroundColor: '#f1f2f3', borderRadius: 10 }, props.style]} />
163
- )
164
- }
165
-
166
- return (
167
- <FastImage key={b_uri + uri} {...props} source={{ uri: uri }} style={props.style} resizeMode={resizeMode} />
168
- )
31
+ return <FastImage {...props} resizeMode={resizeMode} />
169
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.124-s",
3
+ "version": "0.0.124-u",
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",