@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.
Files changed (38) hide show
  1. package/build/commonjs/ComicViewer/ComicViewer.js +197 -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/ReloadButton.js +43 -0
  6. package/build/commonjs/ComicViewer/ReloadButton.js.map +1 -0
  7. package/build/commonjs/ComicViewer/ViewerItem.js +37 -171
  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 -143
  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 -173
  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 +14 -89
  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 +212 -157
  28. package/src/ComicViewer/ComicViewerProps.ts +14 -106
  29. package/src/ComicViewer/ReloadButton.tsx +33 -0
  30. package/src/ComicViewer/ViewerItem.tsx +81 -184
  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,191 +1,57 @@
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 { IconButton, Image, Spacer } from '@fountain-ui/core';
5
- import { Restart } from '@fountain-ui/icons';
6
- import { STATE } from './ComicViewerProps';
7
-
8
- const useStyles = function () {
9
- return {
10
- root: {
11
- display: 'flex',
12
- flexDirection: 'row',
13
- justifyContent: 'center'
14
- },
15
- reload: {
16
- display: 'flex',
17
- alignItems: 'center'
18
- }
19
- };
20
- };
21
-
22
- function ViewerItem(_ref) {
23
- var _itemState$error;
24
-
25
- let {
26
- props
27
- } = _ref;
1
+ import React, { useMemo } from 'react';
2
+ import { Image, TouchableWithoutFeedback, View } from 'react-native';
3
+ import { css, Image as FuiImage } from '@fountain-ui/core';
4
+ import ReloadButton from './ReloadButton';
5
+ export default function ViewerItem(props) {
28
6
  const {
29
- expiresAt,
30
- errorRetryCount = 3,
31
7
  height,
32
- itemState,
33
- isViewable,
34
- sortKey,
35
- responseTimestamp,
36
8
  url,
37
9
  width,
38
- getNextPage,
39
10
  onError,
40
- onLoaded,
41
- onItemPress
11
+ onLoad,
12
+ onPress,
13
+ onReloadPress,
14
+ reloadButtonVisible = false
42
15
  } = props;
43
- const [isLoaded, setIsLoaded] = useState(false);
44
- const styles = useStyles();
45
- const errorCount = useRef(R.defaultTo(0)(itemState === null || itemState === void 0 ? void 0 : (_itemState$error = itemState.error) === null || _itemState$error === void 0 ? void 0 : _itemState$error.count));
46
- const onLoad = useCallback(() => {
47
- errorCount.current = 0;
48
- setIsLoaded(true);
49
- onLoaded && onLoaded(sortKey);
50
- }, [sortKey, onLoaded]);
51
- const handleError = useCallback(() => {
52
- errorCount.current = errorCount.current + 1;
53
- const now = new Date();
54
- const utcNow = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
55
- const expired = new Date(expiresAt).getTime() <= utcNow;
56
- onError && onError({
57
- sortKey,
58
- count: errorCount.current,
59
- expired
60
- });
61
- }, [errorCount.current, onError]);
62
- const onReloadPress = useCallback(() => {
63
- errorCount.current = 1;
64
- onError && onError({
65
- sortKey,
66
- count: errorCount.current,
67
- expired: false
68
- });
69
- }, [sortKey, onError]);
70
- const viewStyle = {
71
- width: '100%',
72
- height,
73
- ...Platform.select({
74
- web: {
75
- 'cursor': 'default'
76
- }
77
- })
78
- };
79
- const imageStyle = {
80
- width,
81
- height
82
- };
83
- const Placeholder = useCallback(props => {
84
- const {
85
- children,
86
- failed
87
- } = props;
88
-
89
- if (!(isViewable || isLoaded || failed) || (itemState === null || itemState === void 0 ? void 0 : itemState.state) === STATE.FAIL || (itemState === null || itemState === void 0 ? void 0 : itemState.state) === STATE.INIT) {
90
- return /*#__PURE__*/React.createElement(ImageBackground, {
91
- source: {
92
- uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg'
93
- },
94
- resizeMode: "repeat",
95
- style: viewStyle
96
- });
97
- }
98
-
99
- if (errorCount.current >= errorRetryCount) {
100
- return /*#__PURE__*/React.createElement(ImageBackground, {
101
- source: {
102
- uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg'
103
- },
104
- resizeMode: "repeat",
105
- style: [viewStyle, styles.reload]
106
- }, /*#__PURE__*/React.createElement(Spacer, {
107
- size: 20
108
- }), /*#__PURE__*/React.createElement(IconButton, {
109
- children: /*#__PURE__*/React.createElement(Restart, {
110
- fill: '#ffffff'
111
- }),
112
- style: {
113
- width: 48,
114
- height: 48,
115
- borderRadius: 24,
116
- color: '#ffffff',
117
- backgroundColor: '#767676'
118
- },
119
- onPress: onReloadPress
120
- }));
121
- }
122
-
123
- return /*#__PURE__*/React.createElement(ImageBackground, {
124
- source: {
125
- uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg'
126
- },
127
- resizeMode: "repeat",
128
- style: viewStyle
129
- }, children);
130
- }, [isViewable, isLoaded, errorCount.current, itemState === null || itemState === void 0 ? void 0 : itemState.state, responseTimestamp]);
131
- useEffect(() => {
132
- if ((itemState === null || itemState === void 0 ? void 0 : itemState.state) === STATE.INIT) {
133
- getNextPage === null || getNextPage === void 0 ? void 0 : getNextPage(sortKey);
16
+ const styles = {
17
+ view: {
18
+ height,
19
+ width: '100%'
20
+ },
21
+ image: {
22
+ height,
23
+ width
134
24
  }
135
- }, []);
136
- return /*#__PURE__*/React.createElement(TouchableOpacity, {
137
- activeOpacity: 1,
138
- onPress: onItemPress
25
+ };
26
+ const error = reloadButtonVisible ? /*#__PURE__*/React.createElement(ReloadButton, {
27
+ onPress: onReloadPress
28
+ }) : null;
29
+ const placeholder = useMemo(() => /*#__PURE__*/React.createElement(Image, {
30
+ source: require('./checkered-loading.jpg'),
31
+ resizeMode: "repeat",
32
+ style: styles.image
33
+ }), [width]);
34
+ return /*#__PURE__*/React.createElement(TouchableWithoutFeedback, {
35
+ onPress: onPress
139
36
  }, /*#__PURE__*/React.createElement(View, {
140
- style: [styles.root, viewStyle]
141
- }, /*#__PURE__*/React.createElement(Image, {
142
- failDependency: [url, expiresAt, responseTimestamp],
143
- disableOutline: true,
144
- key: sortKey,
145
- disableLongClick: true,
37
+ style: styles.view
38
+ }, /*#__PURE__*/React.createElement(FuiImage, {
146
39
  disableDrag: true,
40
+ disableLongClick: true,
41
+ disableOutline: true,
42
+ error: error,
43
+ onError: onError,
147
44
  onLoad: onLoad,
148
- onError: handleError,
149
45
  loading: 'eager',
46
+ placeholder: placeholder,
150
47
  source: {
151
48
  uri: url
152
49
  },
153
- style: imageStyle,
154
50
  square: true,
155
- Placeholder: Placeholder,
156
- disablePlaceholder: true
51
+ style: css([{
52
+ alignSelf: 'center'
53
+ }, styles.image])
157
54
  })));
158
55
  }
159
-
160
- export default /*#__PURE__*/React.memo(ViewerItem, (prevProps, nextProps) => {
161
- var _prevProps$props$item, _nextProps$props$item, _prevProps$props$item2;
162
-
163
- if (prevProps.props.isViewable !== nextProps.props.isViewable) {
164
- return false;
165
- } // NO NEED ?
166
-
167
-
168
- if (prevProps.props.url !== nextProps.props.url) {
169
- return false;
170
- } // NO NEED ?
171
-
172
-
173
- if (prevProps.props.expiresAt !== nextProps.props.expiresAt) {
174
- return false;
175
- }
176
-
177
- if (prevProps.props.width !== nextProps.props.width) {
178
- return false;
179
- }
180
-
181
- if (((_prevProps$props$item = prevProps.props.itemState) === null || _prevProps$props$item === void 0 ? void 0 : _prevProps$props$item.state) !== ((_nextProps$props$item = nextProps.props.itemState) === null || _nextProps$props$item === void 0 ? void 0 : _nextProps$props$item.state)) {
182
- return false;
183
- }
184
-
185
- if (((_prevProps$props$item2 = prevProps.props.itemState) === null || _prevProps$props$item2 === void 0 ? void 0 : _prevProps$props$item2.state) !== STATE.LOADED && prevProps.props.responseTimestamp !== nextProps.props.responseTimestamp) {
186
- return false;
187
- }
188
-
189
- return true;
190
- });
56
+ ;
191
57
  //# sourceMappingURL=ViewerItem.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","useEffect","useRef","useState","ImageBackground","Platform","TouchableOpacity","View","R","IconButton","Image","Spacer","Restart","STATE","useStyles","root","display","flexDirection","justifyContent","reload","alignItems","ViewerItem","props","expiresAt","errorRetryCount","height","itemState","isViewable","sortKey","responseTimestamp","url","width","getNextPage","onError","onLoaded","onItemPress","isLoaded","setIsLoaded","styles","errorCount","defaultTo","error","count","onLoad","current","handleError","now","Date","utcNow","getTime","getTimezoneOffset","expired","onReloadPress","viewStyle","select","web","imageStyle","Placeholder","children","failed","state","FAIL","INIT","uri","borderRadius","color","backgroundColor","memo","prevProps","nextProps","LOADED"],"sources":["ViewerItem.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { ImageBackground, Platform, TouchableOpacity, View } from 'react-native';\nimport * as R from 'ramda';\nimport type { PlaceholderProps } from '@fountain-ui/core';\nimport { IconButton, Image, Spacer } from '@fountain-ui/core';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { Restart } from '@fountain-ui/icons';\nimport ComicViewerItemProps from './ComicViewerItemProps';\nimport { STATE } from './ComicViewerProps';\n\ntype PlaceholderStyles = NamedStylesStringUnion<'reload' | 'root'>;\n\nconst useStyles: UseStyles<PlaceholderStyles> = function (): PlaceholderStyles {\n return {\n root: {\n display: 'flex',\n flexDirection: 'row',\n justifyContent: 'center',\n },\n reload: {\n display: 'flex',\n alignItems: 'center',\n },\n };\n};\n\nfunction ViewerItem<T>({ props }: { props: ComicViewerItemProps<T> }) {\n const {\n expiresAt,\n errorRetryCount = 3,\n height,\n itemState,\n isViewable,\n sortKey,\n responseTimestamp,\n url,\n width,\n getNextPage,\n onError,\n onLoaded,\n onItemPress,\n } = props;\n\n const [isLoaded, setIsLoaded] = useState(false);\n\n const styles = useStyles();\n\n const errorCount = useRef<number>(R.defaultTo(0)(itemState?.error?.count));\n\n const onLoad = useCallback(() => {\n errorCount.current = 0;\n\n setIsLoaded(true);\n\n onLoaded && onLoaded(sortKey);\n }, [sortKey, onLoaded]);\n\n const handleError = useCallback(() => {\n errorCount.current = errorCount.current + 1;\n\n const now = new Date();\n const utcNow = now.getTime() + (now.getTimezoneOffset() * 60 * 1000);\n const expired = new Date(expiresAt).getTime() <= utcNow;\n\n onError && onError({\n sortKey,\n count: errorCount.current,\n expired,\n });\n }, [errorCount.current, onError]);\n\n const onReloadPress = useCallback(() => {\n errorCount.current = 1;\n\n onError && onError({\n sortKey,\n count: errorCount.current,\n expired: false,\n });\n }, [sortKey, onError]);\n\n const viewStyle = {\n width: '100%',\n height,\n ...Platform.select({\n web: { 'cursor': 'default' },\n }),\n };\n\n const imageStyle = { width, height };\n\n const Placeholder = useCallback((props: PlaceholderProps) => {\n const { children, failed } = props;\n\n if (!(isViewable || isLoaded || failed)\n || (itemState?.state === STATE.FAIL)\n || itemState?.state === STATE.INIT\n ) {\n return <ImageBackground\n source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}\n resizeMode=\"repeat\"\n style={viewStyle}\n />;\n }\n\n if (errorCount.current >= errorRetryCount) {\n return <ImageBackground\n source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}\n resizeMode=\"repeat\"\n style={[\n viewStyle,\n styles.reload,\n ]}\n >\n <Spacer size={20}/>\n\n <IconButton\n children={<Restart fill={'#ffffff'}/>}\n style={{\n width: 48,\n height: 48,\n borderRadius: 24,\n color: '#ffffff',\n backgroundColor: '#767676',\n }}\n onPress={onReloadPress}\n />\n </ImageBackground>;\n }\n\n return <ImageBackground\n source={{ uri: 'https://ssl.pstatic.net/static/m/comic/im/2012/bg_viewbody.jpg' }}\n resizeMode=\"repeat\"\n style={viewStyle}\n >\n {children}\n </ImageBackground>;\n }, [isViewable, isLoaded, errorCount.current, itemState?.state, responseTimestamp]);\n\n useEffect(() => {\n if (itemState?.state === STATE.INIT) {\n getNextPage?.(sortKey);\n }\n }, []);\n\n return (\n <TouchableOpacity\n activeOpacity={1}\n onPress={onItemPress}\n >\n <View\n style={[\n styles.root,\n viewStyle,\n ]}\n >\n <Image\n failDependency={[url, expiresAt, responseTimestamp]}\n disableOutline={true}\n key={sortKey}\n disableLongClick={true}\n disableDrag={true}\n onLoad={onLoad}\n onError={handleError}\n loading={'eager'}\n source={{ uri: url }}\n style={imageStyle}\n square={true}\n Placeholder={Placeholder}\n disablePlaceholder={true}\n />\n </View>\n </TouchableOpacity>\n );\n}\n\nexport default React.memo(ViewerItem, (prevProps, nextProps) => {\n if (prevProps.props.isViewable !== nextProps.props.isViewable) {\n return false;\n }\n\n // NO NEED ?\n if (prevProps.props.url !== nextProps.props.url) {\n return false;\n }\n\n // NO NEED ?\n if (prevProps.props.expiresAt !== nextProps.props.expiresAt) {\n return false;\n }\n\n if (prevProps.props.width !== nextProps.props.width) {\n return false;\n }\n\n if (prevProps.props.itemState?.state !== nextProps.props.itemState?.state) {\n return false;\n }\n\n if (prevProps.props.itemState?.state !== STATE.LOADED && prevProps.props.responseTimestamp !== nextProps.props.responseTimestamp) {\n return false;\n }\n\n return true;\n});"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,MAAxC,EAAgDC,QAAhD,QAAgE,OAAhE;AACA,SAASC,eAAT,EAA0BC,QAA1B,EAAoCC,gBAApC,EAAsDC,IAAtD,QAAkE,cAAlE;AACA,OAAO,KAAKC,CAAZ,MAAmB,OAAnB;AAEA,SAASC,UAAT,EAAqBC,KAArB,EAA4BC,MAA5B,QAA0C,mBAA1C;AAEA,SAASC,OAAT,QAAwB,oBAAxB;AAEA,SAASC,KAAT,QAAsB,oBAAtB;;AAIA,MAAMC,SAAuC,GAAG,YAA+B;EAC3E,OAAO;IACHC,IAAI,EAAE;MACFC,OAAO,EAAE,MADP;MAEFC,aAAa,EAAE,KAFb;MAGFC,cAAc,EAAE;IAHd,CADH;IAMHC,MAAM,EAAE;MACJH,OAAO,EAAE,MADL;MAEJI,UAAU,EAAE;IAFR;EANL,CAAP;AAWH,CAZD;;AAcA,SAASC,UAAT,OAAsE;EAAA;;EAAA,IAA/C;IAAEC;EAAF,CAA+C;EAClE,MAAM;IACFC,SADE;IAEFC,eAAe,GAAG,CAFhB;IAGFC,MAHE;IAIFC,SAJE;IAKFC,UALE;IAMFC,OANE;IAOFC,iBAPE;IAQFC,GARE;IASFC,KATE;IAUFC,WAVE;IAWFC,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ouchableWithoutFeedback","View","css","FuiImage","ReloadButton","ViewerItem","props","height","url","width","onError","onLoad","onPress","onReloadPress","reloadButtonVisible","styles","view","image","error","placeholder","require","uri","alignSelf"],"sources":["ViewerItem.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Image, TouchableWithoutFeedback, View } from 'react-native';\nimport { css, Image as FuiImage, ImageProps } from '@fountain-ui/core';\nimport ReloadButton from './ReloadButton';\n\nexport interface ViewerItemProps {\n /**\n * Image width.\n */\n width: number;\n\n /**\n * Image height.\n */\n height: number;\n\n /**\n * Image sourceUrl for displaying.\n */\n url?: string;\n\n /**\n * Error handler.\n */\n onError?: ImageProps['onError'];\n\n /**\n * Load handler.\n */\n onLoad?: ImageProps['onLoad'];\n\n /**\n * Handle Reload button press event.\n */\n onReloadPress?: ImageProps['onError'];\n\n /**\n * Handle item press event.\n */\n onPress?: () => void;\n\n /**\n * If true, reload button visible.\n * @default false\n */\n reloadButtonVisible?: boolean;\n}\n\nexport default function ViewerItem(props: ViewerItemProps) {\n const {\n height,\n url,\n width,\n onError,\n onLoad,\n onPress,\n onReloadPress,\n reloadButtonVisible = false,\n } = props;\n\n const styles = {\n view: {\n height,\n width: '100%',\n },\n image: {\n height,\n width,\n },\n };\n\n const error = reloadButtonVisible ? <ReloadButton onPress={onReloadPress}/> : null;\n\n const placeholder = useMemo(() => <Image\n source={require('./checkered-loading.jpg')}\n resizeMode=\"repeat\"\n style={styles.image}\n />, [width]);\n\n return (\n <TouchableWithoutFeedback onPress={onPress}>\n <View style={styles.view}>\n <FuiImage\n disableDrag={true}\n disableLongClick={true}\n disableOutline={true}\n error={error}\n onError={onError}\n onLoad={onLoad}\n loading={'eager'}\n placeholder={placeholder}\n source={{ uri: url }}\n square={true}\n style={css([\n { alignSelf: 'center' },\n styles.image,\n ])}\n />\n </View>\n </TouchableWithoutFeedback>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,OAAhB,QAA+B,OAA/B;AACA,SAASC,KAA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AS,EAAE;IAAb,CADO,EAEPP,MAAM,CAACE,KAFA,CAAD;EAXd,EADJ,CADJ,CADJ;AAsBH;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './ComicViewer';\nexport type { ComicViewerItemData, default as ComicViewerProps, ErrorInfo } from './ComicViewerProps';\nexport type { default as ComicViewerItemProps } from './ComicViewerItemProps';"],"mappings":"AAAA,SAASA,OAAT,QAAwB,eAAxB"}
1
+ {"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './ComicViewer';\nexport type { Dimension, default as ComicViewerProps } from './ComicViewerProps';\nexport type { ViewerItemProps } from './ViewerItem';\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,eAAxB"}
@@ -1,2 +1,2 @@
1
1
  import { default as ComicViewerProps } from './ComicViewerProps';
2
- export default function ComicViewer<T>(props: ComicViewerProps<T>): JSX.Element;
2
+ export default function ComicViewer(props: ComicViewerProps): JSX.Element;
@@ -1,86 +1,21 @@
1
1
  import React from 'react';
2
2
  import { ComponentProps } from '@fountain-ui/core';
3
3
  import { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
4
- export declare const STATE: {
5
- readonly INIT: "init";
6
- readonly URL_LOADED: "url_loaded";
7
- readonly LOADED: "loaded";
8
- readonly FAIL: "fail";
9
- };
10
- export declare type LoadingState = typeof STATE[keyof typeof STATE];
11
- export interface ComicViewerItemState {
12
- /**
13
- * Comic viewer item sortKey.
14
- */
15
- sortKey: number;
16
- /**
17
- * Content's loading state.
18
- */
19
- state: LoadingState;
20
- /***
21
- * Content's error Info.
22
- */
23
- error?: ErrorInfo;
24
- }
25
- export interface ErrorInfo {
26
- /**
27
- * ComicViewerItemData.sortKey.
28
- */
29
- sortKey: number;
30
- /**
31
- * Number of times an error occurred.
32
- */
33
- count: number;
34
- /**
35
- * Content is Expired: true
36
- */
37
- expired: boolean;
38
- }
39
- export declare type ComicViewerItemData<T = {}> = T & {
40
- /**
41
- * Image height.
42
- */
43
- height: number;
44
- /**
45
- * Unique value for identifying.
46
- */
47
- id: number | undefined;
48
- /**
49
- * Image sourceUrl for displaying.
50
- */
51
- url: string;
52
- /**
53
- * Image width.
54
- */
4
+ export interface Dimension {
55
5
  width: number;
56
- /**
57
- * SortKey
58
- */
59
- sortKey: number;
60
- /**
61
- * Image expire date.
62
- */
63
- expiresAt: string;
64
- /***
65
- * Timestamp when get content response
66
- */
67
- responseTimestamp: number;
68
- };
69
- export default interface ComicViewerProps<T> extends ComponentProps<{
70
- /**
71
- * Data for render.
72
- */
73
- data: ComicViewerItemData<T>[];
6
+ height: number;
7
+ }
8
+ export default interface ComicViewerProps extends ComponentProps<{
74
9
  /**
75
10
  * Delay Time to call the error handler.
76
11
  * @default 500
77
12
  */
78
- errorDebounceMillis?: number;
13
+ debounceMillis?: number;
79
14
  /**
80
- * How many times retry onError when same item error occur
15
+ * How many times handle onError directly when item error occur
81
16
  * @default 3
82
17
  */
83
- errorRetryCount?: number;
18
+ autoHandleErrorCount?: number;
84
19
  /**
85
20
  * How many items to render in the initial batch.
86
21
  * @default 1
@@ -97,33 +32,23 @@ export default interface ComicViewerProps<T> extends ComponentProps<{
97
32
  * @default 0
98
33
  */
99
34
  itemVisiblePercentThreshold?: number;
100
- /***
101
- * Timestamp when get content response
35
+ /**
36
+ * Dimensions of each Image considering viewport.
102
37
  */
103
- responseTimestamp: number;
38
+ intrinsicDimensions: Array<Dimension>;
104
39
  /**
105
- * Comic viewer width.
40
+ * TBD
106
41
  */
107
- viewerWidth: number;
42
+ viewportWidth: number;
108
43
  /**
109
44
  * The value for FlatList windowSize.
110
45
  * @default 3
111
46
  */
112
47
  windowSize?: number;
113
48
  /**
114
- * How many images in one page.
115
- */
116
- pageUnit: number;
117
- /**
118
- * Method for getting next page contents.
119
- * @param sortKey
120
- */
121
- getNextPage?: (sortKey: number) => void;
122
- /**
123
- * Handling all viewerItem errors at once.
124
- * @param errors Array of ViewerItems errorInfo.
49
+ * TBD
125
50
  */
126
- onError?: (errors: ErrorInfo[]) => void;
51
+ getUrlByIndex: (indexes: Array<number>) => Promise<Map<number, string> | undefined>;
127
52
  /**
128
53
  * Handle scroll event.
129
54
  * @param event Scroll event.
@@ -0,0 +1,6 @@
1
+ import { IconButtonProps } from '@fountain-ui/core';
2
+ interface ReloadButtonProps {
3
+ onPress: IconButtonProps['onPress'];
4
+ }
5
+ export default function ReloadButton(props: ReloadButtonProps): JSX.Element;
6
+ export {};
@@ -1,7 +1,37 @@
1
- import React from 'react';
2
- import ComicViewerItemProps from './ComicViewerItemProps';
3
- declare function ViewerItem<T>({ props }: {
4
- props: ComicViewerItemProps<T>;
5
- }): JSX.Element;
6
- declare const _default: React.MemoExoticComponent<typeof ViewerItem>;
7
- export default _default;
1
+ import { ImageProps } from '@fountain-ui/core';
2
+ export interface ViewerItemProps {
3
+ /**
4
+ * Image width.
5
+ */
6
+ width: number;
7
+ /**
8
+ * Image height.
9
+ */
10
+ height: number;
11
+ /**
12
+ * Image sourceUrl for displaying.
13
+ */
14
+ url?: string;
15
+ /**
16
+ * Error handler.
17
+ */
18
+ onError?: ImageProps['onError'];
19
+ /**
20
+ * Load handler.
21
+ */
22
+ onLoad?: ImageProps['onLoad'];
23
+ /**
24
+ * Handle Reload button press event.
25
+ */
26
+ onReloadPress?: ImageProps['onError'];
27
+ /**
28
+ * Handle item press event.
29
+ */
30
+ onPress?: () => void;
31
+ /**
32
+ * If true, reload button visible.
33
+ * @default false
34
+ */
35
+ reloadButtonVisible?: boolean;
36
+ }
37
+ export default function ViewerItem(props: ViewerItemProps): JSX.Element;
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fountain-ui/lab",
3
- "version": "2.0.0-beta.34",
3
+ "version": "2.0.0-beta.35",
4
4
  "private": false,
5
5
  "author": "Fountain-UI Team",
6
6
  "description": "Incubator for Fountain-UI React components.",
@@ -70,5 +70,5 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "gitHead": "44aa49c39c8a9f0986b9d12e06a8a2cfc3766ed9"
73
+ "gitHead": "9c4883b57705f114ca21d0796caa0d460024241f"
74
74
  }