@fountain-ui/lab 2.0.0-beta.34 → 2.0.0-beta.35
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 +197 -143
- package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
- package/build/commonjs/ComicViewer/ComicViewerProps.js +0 -12
- package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/commonjs/ComicViewer/ReloadButton.js +43 -0
- package/build/commonjs/ComicViewer/ReloadButton.js.map +1 -0
- package/build/commonjs/ComicViewer/ViewerItem.js +37 -171
- package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
- package/build/commonjs/ComicViewer/checkered-loading.jpg +0 -0
- package/build/commonjs/ComicViewer/index.js.map +1 -1
- package/build/module/ComicViewer/ComicViewer.js +196 -143
- package/build/module/ComicViewer/ComicViewer.js.map +1 -1
- package/build/module/ComicViewer/ComicViewerProps.js +1 -6
- package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/module/ComicViewer/ReloadButton.js +29 -0
- package/build/module/ComicViewer/ReloadButton.js.map +1 -0
- package/build/module/ComicViewer/ViewerItem.js +39 -173
- package/build/module/ComicViewer/ViewerItem.js.map +1 -1
- package/build/module/ComicViewer/checkered-loading.jpg +0 -0
- package/build/module/ComicViewer/index.js.map +1 -1
- package/build/typescript/ComicViewer/ComicViewer.d.ts +1 -1
- package/build/typescript/ComicViewer/ComicViewerProps.d.ts +14 -89
- package/build/typescript/ComicViewer/ReloadButton.d.ts +6 -0
- package/build/typescript/ComicViewer/ViewerItem.d.ts +37 -7
- package/build/typescript/ComicViewer/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/ComicViewer/ComicViewer.tsx +212 -157
- package/src/ComicViewer/ComicViewerProps.ts +14 -106
- package/src/ComicViewer/ReloadButton.tsx +33 -0
- package/src/ComicViewer/ViewerItem.tsx +81 -184
- package/src/ComicViewer/checkered-loading.jpg +0 -0
- package/src/ComicViewer/index.ts +2 -2
- package/build/commonjs/ComicViewer/ComicViewerItemProps.js +0 -6
- package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +0 -1
- package/build/module/ComicViewer/ComicViewerItemProps.js +0 -2
- package/build/module/ComicViewer/ComicViewerItemProps.js.map +0 -1
- package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +0 -34
- package/src/ComicViewer/ComicViewerItemProps.ts +0 -42
|
@@ -1,205 +1,102 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Image, TouchableWithoutFeedback, View } from 'react-native';
|
|
3
|
+
import { css, Image as FuiImage, ImageProps } from '@fountain-ui/core';
|
|
4
|
+
import ReloadButton from './ReloadButton';
|
|
5
|
+
|
|
6
|
+
export interface ViewerItemProps {
|
|
7
|
+
/**
|
|
8
|
+
* Image width.
|
|
9
|
+
*/
|
|
10
|
+
width: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Image height.
|
|
14
|
+
*/
|
|
15
|
+
height: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Image sourceUrl for displaying.
|
|
19
|
+
*/
|
|
20
|
+
url?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Error handler.
|
|
24
|
+
*/
|
|
25
|
+
onError?: ImageProps['onError'];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Load handler.
|
|
29
|
+
*/
|
|
30
|
+
onLoad?: ImageProps['onLoad'];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Handle Reload button press event.
|
|
34
|
+
*/
|
|
35
|
+
onReloadPress?: ImageProps['onError'];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Handle item press event.
|
|
39
|
+
*/
|
|
40
|
+
onPress?: () => void;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* If true, reload button visible.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
reloadButtonVisible?: boolean;
|
|
47
|
+
}
|
|
26
48
|
|
|
27
|
-
function ViewerItem
|
|
49
|
+
export default function ViewerItem(props: ViewerItemProps) {
|
|
28
50
|
const {
|
|
29
|
-
expiresAt,
|
|
30
|
-
errorRetryCount = 3,
|
|
31
51
|
height,
|
|
32
|
-
itemState,
|
|
33
|
-
isViewable,
|
|
34
|
-
sortKey,
|
|
35
|
-
responseTimestamp,
|
|
36
52
|
url,
|
|
37
53
|
width,
|
|
38
|
-
getNextPage,
|
|
39
54
|
onError,
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
onLoad,
|
|
56
|
+
onPress,
|
|
57
|
+
onReloadPress,
|
|
58
|
+
reloadButtonVisible = false,
|
|
42
59
|
} = props;
|
|
43
60
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
setIsLoaded(true);
|
|
54
|
-
|
|
55
|
-
onLoaded && onLoaded(sortKey);
|
|
56
|
-
}, [sortKey, onLoaded]);
|
|
57
|
-
|
|
58
|
-
const handleError = useCallback(() => {
|
|
59
|
-
errorCount.current = errorCount.current + 1;
|
|
60
|
-
|
|
61
|
-
const now = new Date();
|
|
62
|
-
const utcNow = now.getTime() + (now.getTimezoneOffset() * 60 * 1000);
|
|
63
|
-
const expired = new Date(expiresAt).getTime() <= utcNow;
|
|
64
|
-
|
|
65
|
-
onError && onError({
|
|
66
|
-
sortKey,
|
|
67
|
-
count: errorCount.current,
|
|
68
|
-
expired,
|
|
69
|
-
});
|
|
70
|
-
}, [errorCount.current, onError]);
|
|
71
|
-
|
|
72
|
-
const onReloadPress = useCallback(() => {
|
|
73
|
-
errorCount.current = 1;
|
|
74
|
-
|
|
75
|
-
onError && onError({
|
|
76
|
-
sortKey,
|
|
77
|
-
count: errorCount.current,
|
|
78
|
-
expired: false,
|
|
79
|
-
});
|
|
80
|
-
}, [sortKey, onError]);
|
|
81
|
-
|
|
82
|
-
const viewStyle = {
|
|
83
|
-
width: '100%',
|
|
84
|
-
height,
|
|
85
|
-
...Platform.select({
|
|
86
|
-
web: { 'cursor': 'default' },
|
|
87
|
-
}),
|
|
61
|
+
const styles = {
|
|
62
|
+
view: {
|
|
63
|
+
height,
|
|
64
|
+
width: '100%',
|
|
65
|
+
},
|
|
66
|
+
image: {
|
|
67
|
+
height,
|
|
68
|
+
width,
|
|
69
|
+
},
|
|
88
70
|
};
|
|
89
71
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const Placeholder = useCallback((props: PlaceholderProps) => {
|
|
93
|
-
const { children, failed } = props;
|
|
94
|
-
|
|
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
|
-
/>;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (errorCount.current >= errorRetryCount) {
|
|
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
|
-
>
|
|
115
|
-
<Spacer size={20}/>
|
|
116
|
-
|
|
117
|
-
<IconButton
|
|
118
|
-
children={<Restart fill={'#ffffff'}/>}
|
|
119
|
-
style={{
|
|
120
|
-
width: 48,
|
|
121
|
-
height: 48,
|
|
122
|
-
borderRadius: 24,
|
|
123
|
-
color: '#ffffff',
|
|
124
|
-
backgroundColor: '#767676',
|
|
125
|
-
}}
|
|
126
|
-
onPress={onReloadPress}
|
|
127
|
-
/>
|
|
128
|
-
</ImageBackground>;
|
|
129
|
-
}
|
|
130
|
-
|
|
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]);
|
|
72
|
+
const error = reloadButtonVisible ? <ReloadButton onPress={onReloadPress}/> : null;
|
|
139
73
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
74
|
+
const placeholder = useMemo(() => <Image
|
|
75
|
+
source={require('./checkered-loading.jpg')}
|
|
76
|
+
resizeMode="repeat"
|
|
77
|
+
style={styles.image}
|
|
78
|
+
/>, [width]);
|
|
145
79
|
|
|
146
80
|
return (
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
|
|
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}
|
|
81
|
+
<TouchableWithoutFeedback onPress={onPress}>
|
|
82
|
+
<View style={styles.view}>
|
|
83
|
+
<FuiImage
|
|
162
84
|
disableDrag={true}
|
|
85
|
+
disableLongClick={true}
|
|
86
|
+
disableOutline={true}
|
|
87
|
+
error={error}
|
|
88
|
+
onError={onError}
|
|
163
89
|
onLoad={onLoad}
|
|
164
|
-
onError={handleError}
|
|
165
90
|
loading={'eager'}
|
|
91
|
+
placeholder={placeholder}
|
|
166
92
|
source={{ uri: url }}
|
|
167
|
-
style={imageStyle}
|
|
168
93
|
square={true}
|
|
169
|
-
|
|
170
|
-
|
|
94
|
+
style={css([
|
|
95
|
+
{ alignSelf: 'center' },
|
|
96
|
+
styles.image,
|
|
97
|
+
])}
|
|
171
98
|
/>
|
|
172
99
|
</View>
|
|
173
|
-
</
|
|
100
|
+
</TouchableWithoutFeedback>
|
|
174
101
|
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export default React.memo(ViewerItem, (prevProps, nextProps) => {
|
|
178
|
-
if (prevProps.props.isViewable !== nextProps.props.isViewable) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// NO NEED ?
|
|
183
|
-
if (prevProps.props.url !== nextProps.props.url) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// NO NEED ?
|
|
188
|
-
if (prevProps.props.expiresAt !== nextProps.props.expiresAt) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (prevProps.props.width !== nextProps.props.width) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
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
|
-
|
|
204
|
-
return true;
|
|
205
|
-
});
|
|
102
|
+
};
|
|
Binary file
|
package/src/ComicViewer/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './ComicViewer';
|
|
2
|
-
export type {
|
|
3
|
-
export type {
|
|
2
|
+
export type { Dimension, default as ComicViewerProps } from './ComicViewerProps';
|
|
3
|
+
export type { ViewerItemProps } from './ViewerItem';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ComicViewerItemProps.ts"],"sourcesContent":["import { ComicViewerItemData, ErrorInfo, ComicViewerItemState } from './ComicViewerProps';\n\ntype ComicViewerItemProps<T> = ComicViewerItemData<T> & {\n /**\n * FlatListItem is viewable in screen.\n */\n isViewable: boolean;\n\n /**\n * How many times retry onError when same item error occur\n * @default 3\n */\n errorRetryCount?: number;\n\n /**\n * Error handler\n */\n onError?: (errorInfo: ErrorInfo) => void;\n\n /**\n * Load handler\n */\n onLoaded?: (sortKey: number) => void;\n\n /**\n * Method for getting next page contents.\n * @param sortKey\n */\n getNextPage?: (sortKey: number) => void;\n\n /**\n * Handle item press event.\n */\n onItemPress?: () => void;\n\n /**\n * Image loading state and error info.\n */\n itemState?: ComicViewerItemState;\n}\n\nexport default ComicViewerItemProps;"],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ComicViewerItemProps.ts"],"sourcesContent":["import { ComicViewerItemData, ErrorInfo, ComicViewerItemState } from './ComicViewerProps';\n\ntype ComicViewerItemProps<T> = ComicViewerItemData<T> & {\n /**\n * FlatListItem is viewable in screen.\n */\n isViewable: boolean;\n\n /**\n * How many times retry onError when same item error occur\n * @default 3\n */\n errorRetryCount?: number;\n\n /**\n * Error handler\n */\n onError?: (errorInfo: ErrorInfo) => void;\n\n /**\n * Load handler\n */\n onLoaded?: (sortKey: number) => void;\n\n /**\n * Method for getting next page contents.\n * @param sortKey\n */\n getNextPage?: (sortKey: number) => void;\n\n /**\n * Handle item press event.\n */\n onItemPress?: () => void;\n\n /**\n * Image loading state and error info.\n */\n itemState?: ComicViewerItemState;\n}\n\nexport default ComicViewerItemProps;"],"mappings":""}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ComicViewerItemData, ErrorInfo, ComicViewerItemState } from './ComicViewerProps';
|
|
2
|
-
declare type ComicViewerItemProps<T> = ComicViewerItemData<T> & {
|
|
3
|
-
/**
|
|
4
|
-
* FlatListItem is viewable in screen.
|
|
5
|
-
*/
|
|
6
|
-
isViewable: boolean;
|
|
7
|
-
/**
|
|
8
|
-
* How many times retry onError when same item error occur
|
|
9
|
-
* @default 3
|
|
10
|
-
*/
|
|
11
|
-
errorRetryCount?: number;
|
|
12
|
-
/**
|
|
13
|
-
* Error handler
|
|
14
|
-
*/
|
|
15
|
-
onError?: (errorInfo: ErrorInfo) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Load handler
|
|
18
|
-
*/
|
|
19
|
-
onLoaded?: (sortKey: number) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Method for getting next page contents.
|
|
22
|
-
* @param sortKey
|
|
23
|
-
*/
|
|
24
|
-
getNextPage?: (sortKey: number) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Handle item press event.
|
|
27
|
-
*/
|
|
28
|
-
onItemPress?: () => void;
|
|
29
|
-
/**
|
|
30
|
-
* Image loading state and error info.
|
|
31
|
-
*/
|
|
32
|
-
itemState?: ComicViewerItemState;
|
|
33
|
-
};
|
|
34
|
-
export default ComicViewerItemProps;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ComicViewerItemData, ErrorInfo, ComicViewerItemState } from './ComicViewerProps';
|
|
2
|
-
|
|
3
|
-
type ComicViewerItemProps<T> = ComicViewerItemData<T> & {
|
|
4
|
-
/**
|
|
5
|
-
* FlatListItem is viewable in screen.
|
|
6
|
-
*/
|
|
7
|
-
isViewable: boolean;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* How many times retry onError when same item error occur
|
|
11
|
-
* @default 3
|
|
12
|
-
*/
|
|
13
|
-
errorRetryCount?: number;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Error handler
|
|
17
|
-
*/
|
|
18
|
-
onError?: (errorInfo: ErrorInfo) => void;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Load handler
|
|
22
|
-
*/
|
|
23
|
-
onLoaded?: (sortKey: number) => void;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Method for getting next page contents.
|
|
27
|
-
* @param sortKey
|
|
28
|
-
*/
|
|
29
|
-
getNextPage?: (sortKey: number) => void;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Handle item press event.
|
|
33
|
-
*/
|
|
34
|
-
onItemPress?: () => void;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Image loading state and error info.
|
|
38
|
-
*/
|
|
39
|
-
itemState?: ComicViewerItemState;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default ComicViewerItemProps;
|