@fountain-ui/lab 2.0.0-beta.33 → 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.
Files changed (38) hide show
  1. package/build/commonjs/ComicViewer/ComicViewer.js +197 -142
  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/ReloadButton.js +43 -0
  6. package/build/commonjs/ComicViewer/ReloadButton.js.map +1 -0
  7. package/build/commonjs/ComicViewer/ViewerItem.js +37 -152
  8. package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
  9. package/build/commonjs/ComicViewer/checkered-loading.jpg +0 -0
  10. package/build/commonjs/ComicViewer/index.js.map +1 -1
  11. package/build/module/ComicViewer/ComicViewer.js +196 -142
  12. package/build/module/ComicViewer/ComicViewer.js.map +1 -1
  13. package/build/module/ComicViewer/ComicViewerProps.js +1 -6
  14. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
  15. package/build/module/ComicViewer/ReloadButton.js +29 -0
  16. package/build/module/ComicViewer/ReloadButton.js.map +1 -0
  17. package/build/module/ComicViewer/ViewerItem.js +39 -154
  18. package/build/module/ComicViewer/ViewerItem.js.map +1 -1
  19. package/build/module/ComicViewer/checkered-loading.jpg +0 -0
  20. package/build/module/ComicViewer/index.js.map +1 -1
  21. package/build/typescript/ComicViewer/ComicViewer.d.ts +1 -1
  22. package/build/typescript/ComicViewer/ComicViewerProps.d.ts +15 -82
  23. package/build/typescript/ComicViewer/ReloadButton.d.ts +6 -0
  24. package/build/typescript/ComicViewer/ViewerItem.d.ts +37 -7
  25. package/build/typescript/ComicViewer/index.d.ts +2 -2
  26. package/package.json +2 -2
  27. package/src/ComicViewer/ComicViewer.tsx +210 -155
  28. package/src/ComicViewer/ComicViewerProps.ts +16 -98
  29. package/src/ComicViewer/ReloadButton.tsx +33 -0
  30. package/src/ComicViewer/ViewerItem.tsx +81 -169
  31. package/src/ComicViewer/checkered-loading.jpg +0 -0
  32. package/src/ComicViewer/index.ts +2 -2
  33. package/build/commonjs/ComicViewer/ComicViewerItemProps.js +0 -6
  34. package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +0 -1
  35. package/build/module/ComicViewer/ComicViewerItemProps.js +0 -2
  36. package/build/module/ComicViewer/ComicViewerItemProps.js.map +0 -1
  37. package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +0 -34
  38. package/src/ComicViewer/ComicViewerItemProps.ts +0 -42
@@ -1,190 +1,102 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import { 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, useTheme } 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<'init' | 'failed' | 'reload' | 'root'>;
12
-
13
- const useStyles: UseStyles<PlaceholderStyles> = function (): PlaceholderStyles {
14
- const theme = useTheme();
15
-
16
- return {
17
- root: {
18
- display: 'flex',
19
- flexDirection: 'row',
20
- justifyContent: 'center',
21
- },
22
- init: {
23
- backgroundColor: theme.palette.paper.grey,
24
- },
25
- failed: {
26
- backgroundColor: theme.palette.paper.grey,
27
- },
28
- reload: {
29
- backgroundColor: theme.palette.paper.grey,
30
- display: 'flex',
31
- alignItems: 'center',
32
- },
33
- };
34
- };
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
+ }
35
48
 
36
- function ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {
49
+ export default function ViewerItem(props: ViewerItemProps) {
37
50
  const {
38
- expiresAt,
39
- errorRetryCount = 3,
40
51
  height,
41
- itemState,
42
- isViewable,
43
- sortKey,
44
52
  url,
45
53
  width,
46
- getNextPage,
47
54
  onError,
48
- onLoaded,
49
- onItemPress,
55
+ onLoad,
56
+ onPress,
57
+ onReloadPress,
58
+ reloadButtonVisible = false,
50
59
  } = props;
51
60
 
52
- const [isLoaded, setIsLoaded] = useState(false);
53
-
54
- const styles = useStyles();
55
-
56
- const errorCount = useRef<number>(R.defaultTo(0)(itemState?.error?.count));
57
-
58
- const onLoad = useCallback(() => {
59
- errorCount.current = 0;
60
-
61
- setIsLoaded(true);
62
-
63
- onLoaded && onLoaded(sortKey);
64
- }, [sortKey]);
65
-
66
- const handleError = useCallback(() => {
67
- errorCount.current = errorCount.current + 1;
68
-
69
- const now = new Date();
70
- const utcNow = now.getTime() + (now.getTimezoneOffset() * 60 * 1000);
71
- const expired = new Date(expiresAt).getTime() <= utcNow;
72
-
73
- onError && onError({
74
- sortKey,
75
- count: errorCount.current,
76
- expired,
77
- });
78
- }, [errorCount.current]);
79
-
80
- const onReloadPress = useCallback(() => {
81
- errorCount.current = 1;
82
-
83
- onError && onError({
84
- sortKey,
85
- count: errorCount.current,
86
- expired: false,
87
- });
88
- }, [sortKey]);
89
-
90
- const viewStyle = {
91
- width: '100%',
92
- height,
93
- ...Platform.select({
94
- web: { 'cursor': 'default' },
95
- }),
61
+ const styles = {
62
+ view: {
63
+ height,
64
+ width: '100%',
65
+ },
66
+ image: {
67
+ height,
68
+ width,
69
+ },
96
70
  };
97
71
 
98
- const imageStyle = { width, height };
99
-
100
- const Placeholder = useCallback((props: PlaceholderProps) => {
101
- const { children, failed } = props;
102
-
103
- if (!(isViewable || isLoaded)
104
- || failed
105
- || itemState?.state === STATE.INIT
106
- ) {
107
- return <View style={[
108
- viewStyle,
109
- styles.init,
110
- ]}/>;
111
- }
72
+ const error = reloadButtonVisible ? <ReloadButton onPress={onReloadPress}/> : null;
112
73
 
113
- if (errorCount.current >= errorRetryCount) {
114
- return <View style={[
115
- viewStyle,
116
- styles.reload,
117
- ]}>
118
- <Spacer size={20}/>
119
-
120
- <IconButton
121
- children={<Restart fill={'#ffffff'}/>}
122
- style={{
123
- width: 48,
124
- height: 48,
125
- borderRadius: 24,
126
- color: '#ffffff',
127
- backgroundColor: '#767676',
128
- }}
129
- onPress={onReloadPress}
130
- />
131
- </View>;
132
- }
133
-
134
- return children;
135
- }, [isViewable, isLoaded, errorCount.current, url, onItemPress]);
136
-
137
- useEffect(() => {
138
- if (itemState?.state === STATE.INIT) {
139
- getNextPage?.(sortKey);
140
- }
141
- }, []);
74
+ const placeholder = useMemo(() => <Image
75
+ source={require('./checkered-loading.jpg')}
76
+ resizeMode="repeat"
77
+ style={styles.image}
78
+ />, [width]);
142
79
 
143
80
  return (
144
- <TouchableOpacity
145
- activeOpacity={1}
146
- onPress={onItemPress}
147
- >
148
- <View
149
- style={[
150
- styles.root,
151
- viewStyle,
152
- ]}
153
- >
154
- <Image
155
- disableOutline={true}
156
- key={sortKey}
157
- disableLongClick={true}
81
+ <TouchableWithoutFeedback onPress={onPress}>
82
+ <View style={styles.view}>
83
+ <FuiImage
158
84
  disableDrag={true}
85
+ disableLongClick={true}
86
+ disableOutline={true}
87
+ error={error}
88
+ onError={onError}
159
89
  onLoad={onLoad}
160
- onError={handleError}
161
90
  loading={'eager'}
91
+ placeholder={placeholder}
162
92
  source={{ uri: url }}
163
- style={imageStyle}
164
93
  square={true}
165
- Placeholder={Placeholder}
94
+ style={css([
95
+ { alignSelf: 'center' },
96
+ styles.image,
97
+ ])}
166
98
  />
167
99
  </View>
168
- </TouchableOpacity>
100
+ </TouchableWithoutFeedback>
169
101
  );
170
- }
171
-
172
- export default React.memo(ViewerItem, (prevProps, nextProps) => {
173
- if (prevProps.props.isViewable !== nextProps.props.isViewable) {
174
- return false;
175
- }
176
-
177
- if (prevProps.props.url !== nextProps.props.url) {
178
- return false;
179
- }
180
-
181
- if (prevProps.props.width !== nextProps.props.width) {
182
- return false;
183
- }
184
-
185
- if (prevProps.props.itemState?.state !== nextProps.props.itemState?.state) {
186
- return false;
187
- }
188
-
189
- return true;
190
- });
102
+ };
@@ -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;