@fountain-ui/lab 2.0.0-beta.34 → 2.0.0-beta.36

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.
Files changed (41) hide show
  1. package/build/commonjs/ComicViewer/ComicViewer.js +196 -143
  2. package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
  3. package/build/commonjs/ComicViewer/ComicViewerProps.js +0 -12
  4. package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
  5. package/build/commonjs/ComicViewer/EncodedTile.js +10 -0
  6. package/build/commonjs/ComicViewer/EncodedTile.js.map +1 -0
  7. package/build/commonjs/ComicViewer/ReloadButton.js +48 -0
  8. package/build/commonjs/ComicViewer/ReloadButton.js.map +1 -0
  9. package/build/commonjs/ComicViewer/ViewerItem.js +41 -173
  10. package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
  11. package/build/commonjs/ComicViewer/index.js.map +1 -1
  12. package/build/module/ComicViewer/ComicViewer.js +195 -143
  13. package/build/module/ComicViewer/ComicViewer.js.map +1 -1
  14. package/build/module/ComicViewer/ComicViewerProps.js +1 -6
  15. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
  16. package/build/module/ComicViewer/EncodedTile.js +3 -0
  17. package/build/module/ComicViewer/EncodedTile.js.map +1 -0
  18. package/build/module/ComicViewer/ReloadButton.js +33 -0
  19. package/build/module/ComicViewer/ReloadButton.js.map +1 -0
  20. package/build/module/ComicViewer/ViewerItem.js +42 -173
  21. package/build/module/ComicViewer/ViewerItem.js.map +1 -1
  22. package/build/module/ComicViewer/index.js.map +1 -1
  23. package/build/typescript/ComicViewer/ComicViewer.d.ts +1 -1
  24. package/build/typescript/ComicViewer/ComicViewerProps.d.ts +15 -90
  25. package/build/typescript/ComicViewer/EncodedTile.d.ts +2 -0
  26. package/build/typescript/ComicViewer/ReloadButton.d.ts +6 -0
  27. package/build/typescript/ComicViewer/ViewerItem.d.ts +37 -7
  28. package/build/typescript/ComicViewer/index.d.ts +2 -2
  29. package/package.json +2 -2
  30. package/src/ComicViewer/ComicViewer.tsx +210 -157
  31. package/src/ComicViewer/ComicViewerProps.ts +15 -107
  32. package/src/ComicViewer/EncodedTile.ts +3 -0
  33. package/src/ComicViewer/ReloadButton.tsx +36 -0
  34. package/src/ComicViewer/ViewerItem.tsx +82 -184
  35. package/src/ComicViewer/index.ts +2 -2
  36. package/build/commonjs/ComicViewer/ComicViewerItemProps.js +0 -6
  37. package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +0 -1
  38. package/build/module/ComicViewer/ComicViewerItemProps.js +0 -2
  39. package/build/module/ComicViewer/ComicViewerItemProps.js.map +0 -1
  40. package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +0 -34
  41. package/src/ComicViewer/ComicViewerItemProps.ts +0 -42
@@ -1,205 +1,103 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import { ImageBackground, Platform, TouchableOpacity, View } from 'react-native';
3
- import * as R from 'ramda';
4
- import type { PlaceholderProps } from '@fountain-ui/core';
5
- import { IconButton, Image, Spacer } from '@fountain-ui/core';
6
- import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
7
- import { Restart } from '@fountain-ui/icons';
8
- import ComicViewerItemProps from './ComicViewerItemProps';
9
- import { STATE } from './ComicViewerProps';
10
-
11
- type PlaceholderStyles = NamedStylesStringUnion<'reload' | 'root'>;
12
-
13
- const useStyles: UseStyles<PlaceholderStyles> = function (): PlaceholderStyles {
14
- return {
15
- root: {
16
- display: 'flex',
17
- flexDirection: 'row',
18
- justifyContent: 'center',
19
- },
20
- reload: {
21
- display: 'flex',
22
- alignItems: 'center',
23
- },
24
- };
25
- };
1
+ import React 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
+ import EncodedTile from './EncodedTile';
6
+
7
+ export interface ViewerItemProps {
8
+ /**
9
+ * Image width.
10
+ */
11
+ width: number;
12
+
13
+ /**
14
+ * Image height.
15
+ */
16
+ height: number;
17
+
18
+ /**
19
+ * Image sourceUrl for displaying.
20
+ */
21
+ url?: string;
22
+
23
+ /**
24
+ * Error handler.
25
+ */
26
+ onError?: ImageProps['onError'];
27
+
28
+ /**
29
+ * Load handler.
30
+ */
31
+ onLoad?: ImageProps['onLoad'];
32
+
33
+ /**
34
+ * Handle Reload button press event.
35
+ */
36
+ onReloadPress?: ImageProps['onError'];
37
+
38
+ /**
39
+ * Handle item press event.
40
+ */
41
+ onPress?: () => void;
42
+
43
+ /**
44
+ * If true, reload button visible.
45
+ * @default false
46
+ */
47
+ reloadButtonVisible?: boolean;
48
+ }
26
49
 
27
- function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
50
+ export default function ViewerItem(props: ViewerItemProps) {
28
51
  const {
29
- expiresAt,
30
- errorRetryCount = 3,
31
52
  height,
32
- itemState,
33
- isViewable,
34
- sortKey,
35
- responseTimestamp,
36
53
  url,
37
54
  width,
38
- getNextPage,
39
55
  onError,
40
- onLoaded,
41
- onItemPress,
56
+ onLoad,
57
+ onPress,
58
+ onReloadPress,
59
+ reloadButtonVisible = false,
42
60
  } = props;
43
61
 
44
- const [isLoaded, setIsLoaded] = useState(false);
45
-
46
- const styles = useStyles();
47
-
48
- const errorCount = useRef<number>(R.defaultTo(0)(itemState?.error?.count));
49
-
50
- const onLoad = useCallback(() => {
51
- errorCount.current = 0;
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
- }),
62
+ const styles = {
63
+ view: {
64
+ height,
65
+ width: '100%',
66
+ },
67
+ image: {
68
+ height,
69
+ width,
70
+ },
88
71
  };
89
72
 
90
- const imageStyle = { width, height };
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]);
73
+ const error = reloadButtonVisible ? <ReloadButton onPress={onReloadPress}/> : null;
139
74
 
140
- useEffect(() => {
141
- if (itemState?.state === STATE.INIT) {
142
- getNextPage?.(sortKey);
143
- }
144
- }, []);
75
+ const placeholder = <Image
76
+ source={{ uri: EncodedTile }}
77
+ resizeMode={'cover'}
78
+ style={styles.image}
79
+ />;
145
80
 
146
81
  return (
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}
82
+ <TouchableWithoutFeedback onPress={onPress}>
83
+ <View style={styles.view}>
84
+ <FuiImage
162
85
  disableDrag={true}
86
+ disableLongClick={true}
87
+ disableOutline={true}
88
+ error={error}
89
+ onError={onError}
163
90
  onLoad={onLoad}
164
- onError={handleError}
165
91
  loading={'eager'}
92
+ placeholder={placeholder}
166
93
  source={{ uri: url }}
167
- style={imageStyle}
168
94
  square={true}
169
- Placeholder={Placeholder}
170
- disablePlaceholder={true}
95
+ style={css([
96
+ { alignSelf: 'center' },
97
+ styles.image,
98
+ ])}
171
99
  />
172
100
  </View>
173
- </TouchableOpacity>
101
+ </TouchableWithoutFeedback>
174
102
  );
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
- });
103
+ };
@@ -1,3 +1,3 @@
1
1
  export { default } from './ComicViewer';
2
- export type { ComicViewerItemData, default as ComicViewerProps, ErrorInfo } from './ComicViewerProps';
3
- export type { default as ComicViewerItemProps } from './ComicViewerItemProps';
2
+ export type { Dimension, default as ComicViewerProps } from './ComicViewerProps';
3
+ export type { ViewerItemProps } from './ViewerItem';
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=ComicViewerItemProps.js.map
@@ -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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ComicViewerItemProps.js.map
@@ -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;