@fountain-ui/lab 2.0.0-beta.32 → 2.0.0-beta.34
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/build/commonjs/ComicViewer/ComicViewer.js +20 -6
- package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
- package/build/commonjs/ComicViewer/ComicViewerProps.js +2 -2
- package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/commonjs/ComicViewer/ViewerItem.js +63 -32
- package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
- package/build/module/ComicViewer/ComicViewer.js +20 -6
- package/build/module/ComicViewer/ComicViewer.js.map +1 -1
- package/build/module/ComicViewer/ComicViewerProps.js +2 -2
- package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/module/ComicViewer/ViewerItem.js +64 -34
- package/build/module/ComicViewer/ViewerItem.js.map +1 -1
- package/build/typescript/ComicViewer/ComicViewerProps.d.ts +10 -2
- package/package.json +2 -2
- package/src/ComicViewer/ComicViewer.tsx +30 -11
- package/src/ComicViewer/ComicViewerProps.ts +12 -2
- package/src/ComicViewer/ViewerItem.tsx +86 -58
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ImageBackground, Platform, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import * as R from 'ramda';
|
|
4
4
|
import type { PlaceholderProps } from '@fountain-ui/core';
|
|
5
|
-
import { IconButton, Image, Spacer
|
|
5
|
+
import { IconButton, Image, Spacer } from '@fountain-ui/core';
|
|
6
6
|
import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
|
|
7
7
|
import { Restart } from '@fountain-ui/icons';
|
|
8
8
|
import ComicViewerItemProps from './ComicViewerItemProps';
|
|
9
|
+
import { STATE } from './ComicViewerProps';
|
|
9
10
|
|
|
10
|
-
type PlaceholderStyles = NamedStylesStringUnion<'
|
|
11
|
+
type PlaceholderStyles = NamedStylesStringUnion<'reload' | 'root'>;
|
|
11
12
|
|
|
12
13
|
const useStyles: UseStyles<PlaceholderStyles> = function (): PlaceholderStyles {
|
|
13
|
-
const theme = useTheme();
|
|
14
|
-
|
|
15
14
|
return {
|
|
16
15
|
root: {
|
|
17
16
|
display: 'flex',
|
|
18
17
|
flexDirection: 'row',
|
|
19
18
|
justifyContent: 'center',
|
|
20
19
|
},
|
|
21
|
-
init: {
|
|
22
|
-
backgroundColor: theme.palette.paper.grey,
|
|
23
|
-
},
|
|
24
|
-
failed: {
|
|
25
|
-
backgroundColor: theme.palette.paper.grey,
|
|
26
|
-
},
|
|
27
20
|
reload: {
|
|
28
|
-
backgroundColor: theme.palette.paper.grey,
|
|
29
21
|
display: 'flex',
|
|
30
22
|
alignItems: 'center',
|
|
31
23
|
},
|
|
@@ -40,6 +32,7 @@ function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
|
|
|
40
32
|
itemState,
|
|
41
33
|
isViewable,
|
|
42
34
|
sortKey,
|
|
35
|
+
responseTimestamp,
|
|
43
36
|
url,
|
|
44
37
|
width,
|
|
45
38
|
getNextPage,
|
|
@@ -60,7 +53,7 @@ function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
|
|
|
60
53
|
setIsLoaded(true);
|
|
61
54
|
|
|
62
55
|
onLoaded && onLoaded(sortKey);
|
|
63
|
-
}, [sortKey]);
|
|
56
|
+
}, [sortKey, onLoaded]);
|
|
64
57
|
|
|
65
58
|
const handleError = useCallback(() => {
|
|
66
59
|
errorCount.current = errorCount.current + 1;
|
|
@@ -74,7 +67,7 @@ function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
|
|
|
74
67
|
count: errorCount.current,
|
|
75
68
|
expired,
|
|
76
69
|
});
|
|
77
|
-
}, [errorCount.current]);
|
|
70
|
+
}, [errorCount.current, onError]);
|
|
78
71
|
|
|
79
72
|
const onReloadPress = useCallback(() => {
|
|
80
73
|
errorCount.current = 1;
|
|
@@ -84,25 +77,41 @@ function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
|
|
|
84
77
|
count: errorCount.current,
|
|
85
78
|
expired: false,
|
|
86
79
|
});
|
|
87
|
-
}, [sortKey]);
|
|
80
|
+
}, [sortKey, onError]);
|
|
81
|
+
|
|
82
|
+
const viewStyle = {
|
|
83
|
+
width: '100%',
|
|
84
|
+
height,
|
|
85
|
+
...Platform.select({
|
|
86
|
+
web: { 'cursor': 'default' },
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
88
89
|
|
|
89
|
-
const
|
|
90
|
+
const imageStyle = { width, height };
|
|
90
91
|
|
|
91
92
|
const Placeholder = useCallback((props: PlaceholderProps) => {
|
|
92
93
|
const { children, failed } = props;
|
|
93
94
|
|
|
94
|
-
if ((
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (!(isViewable || isLoaded || failed)
|
|
96
|
+
|| (itemState?.state === STATE.FAIL)
|
|
97
|
+
|| itemState?.state === STATE.INIT
|
|
98
|
+
) {
|
|
99
|
+
return <ImageBackground
|
|
100
|
+
source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}
|
|
101
|
+
resizeMode="repeat"
|
|
102
|
+
style={viewStyle}
|
|
103
|
+
/>;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
if (errorCount.current >= errorRetryCount) {
|
|
102
|
-
return <
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
return <ImageBackground
|
|
108
|
+
source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}
|
|
109
|
+
resizeMode="repeat"
|
|
110
|
+
style={[
|
|
111
|
+
viewStyle,
|
|
112
|
+
styles.reload,
|
|
113
|
+
]}
|
|
114
|
+
>
|
|
106
115
|
<Spacer size={20}/>
|
|
107
116
|
|
|
108
117
|
<IconButton
|
|
@@ -116,47 +125,52 @@ function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
|
|
|
116
125
|
}}
|
|
117
126
|
onPress={onReloadPress}
|
|
118
127
|
/>
|
|
119
|
-
</
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (failed) {
|
|
123
|
-
return (
|
|
124
|
-
<View style={[
|
|
125
|
-
viewStyle,
|
|
126
|
-
styles.failed,
|
|
127
|
-
]}/>
|
|
128
|
-
);
|
|
128
|
+
</ImageBackground>;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
return <ImageBackground
|
|
132
|
+
source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}
|
|
133
|
+
resizeMode="repeat"
|
|
134
|
+
style={viewStyle}
|
|
135
|
+
>
|
|
136
|
+
{children}
|
|
137
|
+
</ImageBackground>;
|
|
138
|
+
}, [isViewable, isLoaded, errorCount.current, itemState?.state, responseTimestamp]);
|
|
137
139
|
|
|
138
140
|
useEffect(() => {
|
|
139
|
-
if (
|
|
141
|
+
if (itemState?.state === STATE.INIT) {
|
|
140
142
|
getNextPage?.(sortKey);
|
|
141
143
|
}
|
|
142
144
|
}, []);
|
|
143
145
|
|
|
144
146
|
return (
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
147
|
+
<TouchableOpacity
|
|
148
|
+
activeOpacity={1}
|
|
149
|
+
onPress={onItemPress}
|
|
150
|
+
>
|
|
151
|
+
<View
|
|
152
|
+
style={[
|
|
153
|
+
styles.root,
|
|
154
|
+
viewStyle,
|
|
155
|
+
]}
|
|
156
|
+
>
|
|
157
|
+
<Image
|
|
158
|
+
failDependency={[url, expiresAt, responseTimestamp]}
|
|
159
|
+
disableOutline={true}
|
|
160
|
+
key={sortKey}
|
|
161
|
+
disableLongClick={true}
|
|
162
|
+
disableDrag={true}
|
|
163
|
+
onLoad={onLoad}
|
|
164
|
+
onError={handleError}
|
|
165
|
+
loading={'eager'}
|
|
166
|
+
source={{ uri: url }}
|
|
167
|
+
style={imageStyle}
|
|
168
|
+
square={true}
|
|
169
|
+
Placeholder={Placeholder}
|
|
170
|
+
disablePlaceholder={true}
|
|
171
|
+
/>
|
|
172
|
+
</View>
|
|
173
|
+
</TouchableOpacity>
|
|
160
174
|
);
|
|
161
175
|
}
|
|
162
176
|
|
|
@@ -165,13 +179,27 @@ export default React.memo(ViewerItem, (prevProps, nextProps) => {
|
|
|
165
179
|
return false;
|
|
166
180
|
}
|
|
167
181
|
|
|
182
|
+
// NO NEED ?
|
|
168
183
|
if (prevProps.props.url !== nextProps.props.url) {
|
|
169
184
|
return false;
|
|
170
185
|
}
|
|
171
186
|
|
|
187
|
+
// NO NEED ?
|
|
188
|
+
if (prevProps.props.expiresAt !== nextProps.props.expiresAt) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
172
192
|
if (prevProps.props.width !== nextProps.props.width) {
|
|
173
193
|
return false;
|
|
174
194
|
}
|
|
175
195
|
|
|
196
|
+
if (prevProps.props.itemState?.state !== nextProps.props.itemState?.state) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (prevProps.props.itemState?.state !== STATE.LOADED && prevProps.props.responseTimestamp !== nextProps.props.responseTimestamp) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
176
204
|
return true;
|
|
177
|
-
});
|
|
205
|
+
});
|