@fountain-ui/core 2.0.0-beta.36 → 2.0.0-beta.38
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/Image/Image.js +28 -3
- package/build/commonjs/Image/Image.js.map +1 -1
- package/build/commonjs/Image/ImageProps.js.map +1 -1
- package/build/commonjs/Image/index.js.map +1 -1
- package/build/commonjs/ImageCore/ImageCoreProps.js.map +1 -1
- package/build/commonjs/ImageCore/ImageCoreWeb.js +18 -1
- package/build/commonjs/ImageCore/ImageCoreWeb.js.map +1 -1
- package/build/module/Image/Image.js +25 -4
- package/build/module/Image/Image.js.map +1 -1
- package/build/module/Image/ImageProps.js.map +1 -1
- package/build/module/Image/index.js.map +1 -1
- package/build/module/ImageCore/ImageCoreProps.js.map +1 -1
- package/build/module/ImageCore/ImageCoreWeb.js +19 -1
- package/build/module/ImageCore/ImageCoreWeb.js.map +1 -1
- package/build/typescript/Image/ImageProps.d.ts +22 -0
- package/build/typescript/Image/index.d.ts +1 -0
- package/build/typescript/ImageCore/ImageCoreProps.d.ts +2 -0
- package/package.json +2 -2
- package/src/Image/Image.tsx +45 -23
- package/src/Image/ImageProps.ts +26 -0
- package/src/Image/index.ts +2 -1
- package/src/ImageCore/ImageCoreProps.ts +2 -0
- package/src/ImageCore/ImageCoreWeb.tsx +24 -2
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = Image;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
@@ -15,6 +15,10 @@ var _styles = require("../styles");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
18
22
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
19
23
|
|
|
20
24
|
const useStyles = function () {
|
|
@@ -39,6 +43,8 @@ const useStyles = function () {
|
|
|
39
43
|
function Image(props) {
|
|
40
44
|
const {
|
|
41
45
|
alt,
|
|
46
|
+
disableDrag,
|
|
47
|
+
disableLongClick,
|
|
42
48
|
disableOutline,
|
|
43
49
|
disablePlaceholder,
|
|
44
50
|
loading = 'lazy',
|
|
@@ -50,6 +56,7 @@ function Image(props) {
|
|
|
50
56
|
size,
|
|
51
57
|
onLoad,
|
|
52
58
|
onError,
|
|
59
|
+
Placeholder: PlaceholderComponent,
|
|
53
60
|
...otherProps
|
|
54
61
|
} = props;
|
|
55
62
|
|
|
@@ -65,13 +72,31 @@ function Image(props) {
|
|
|
65
72
|
setFailed(true);
|
|
66
73
|
};
|
|
67
74
|
|
|
75
|
+
const Placeholder = _ref => {
|
|
76
|
+
let {
|
|
77
|
+
failed,
|
|
78
|
+
children
|
|
79
|
+
} = _ref;
|
|
80
|
+
return PlaceholderComponent ? /*#__PURE__*/_react.default.createElement(PlaceholderComponent, {
|
|
81
|
+
children: children,
|
|
82
|
+
failed: failed
|
|
83
|
+
}) : children;
|
|
84
|
+
};
|
|
85
|
+
|
|
68
86
|
const sourceWithSizeParam = { ...source,
|
|
69
87
|
uri: size ? `${source.uri}?size=${size}` : source.uri
|
|
70
88
|
};
|
|
89
|
+
(0, _react.useEffect)(() => {
|
|
90
|
+
setFailed(false);
|
|
91
|
+
}, [sourceWithSizeParam.uri]);
|
|
71
92
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({
|
|
72
93
|
style: (0, _styles.css)([styles.root, !disableOutline ? styles.outlined : undefined, !disablePlaceholder ? styles.placeholder : undefined, !square ? styles.rounded : undefined, style])
|
|
73
|
-
}, otherProps),
|
|
94
|
+
}, otherProps), /*#__PURE__*/_react.default.createElement(Placeholder, {
|
|
95
|
+
failed: failed
|
|
96
|
+
}, !failed ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ImageCore.default, {
|
|
74
97
|
alt: alt,
|
|
98
|
+
disableDrag: disableDrag,
|
|
99
|
+
disableLongClick: disableLongClick,
|
|
75
100
|
height: '100%',
|
|
76
101
|
loading: loading,
|
|
77
102
|
onError: handleError,
|
|
@@ -81,7 +106,7 @@ function Image(props) {
|
|
|
81
106
|
width: '100%'
|
|
82
107
|
}), overlaidChildren ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
83
108
|
style: _styles.StyleSheet.absoluteFill
|
|
84
|
-
}, overlaidChildren) : null);
|
|
109
|
+
}, overlaidChildren) : null) : null));
|
|
85
110
|
}
|
|
86
111
|
|
|
87
112
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useStyles","theme","useTheme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","StyleSheet","hairlineWidth","borderStyle","borderColor","Image","props","alt","disableOutline","disablePlaceholder","loading","overlaidChildren","resizeMode","source","style","square","size","onLoad","onError","otherProps","failed","setFailed","React","useState","styles","handleError","sourceWithSizeParam","uri","css","undefined","absoluteFill"],"sources":["Image.tsx"],"sourcesContent":["import React from 'react';\nimport {
|
|
1
|
+
{"version":3,"names":["useStyles","theme","useTheme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","StyleSheet","hairlineWidth","borderStyle","borderColor","Image","props","alt","disableDrag","disableLongClick","disableOutline","disablePlaceholder","loading","overlaidChildren","resizeMode","source","style","square","size","onLoad","onError","Placeholder","PlaceholderComponent","otherProps","failed","setFailed","React","useState","styles","handleError","children","sourceWithSizeParam","uri","useEffect","css","undefined","absoluteFill"],"sources":["Image.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { View } from 'react-native';\nimport type { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport ImageCore from '../ImageCore';\nimport { css, StyleSheet, useTheme } from '../styles';\nimport type ImageProps from './ImageProps';\nimport { PlaceholderProps } from './ImageProps';\n\ntype ImageStyleKeys =\n | 'root'\n | 'rounded'\n | 'placeholder'\n | 'outlined';\n\ntype ImageStyles = NamedStylesStringUnion<ImageStyleKeys>;\n\nconst useStyles: UseStyles<ImageStyles> = function (): ImageStyles {\n const theme = useTheme();\n\n return {\n root: {},\n rounded: {\n borderRadius: theme.shape.roundness,\n overflow: 'hidden',\n },\n placeholder: {\n backgroundColor: theme.palette.paper.grey,\n },\n outlined: {\n borderWidth: StyleSheet.hairlineWidth,\n borderStyle: 'solid',\n borderColor: theme.palette.paper.grey,\n },\n };\n};\n\nexport default function Image(props: ImageProps) {\n const {\n alt,\n disableDrag,\n disableLongClick,\n disableOutline,\n disablePlaceholder,\n loading = 'lazy',\n overlaidChildren,\n resizeMode = 'cover',\n source,\n style,\n square = false,\n size,\n onLoad,\n onError,\n Placeholder: PlaceholderComponent,\n ...otherProps\n } = props;\n\n const [failed, setFailed] = React.useState(false);\n\n const styles = useStyles();\n\n const handleError = () => {\n if (onError) {\n onError();\n }\n\n setFailed(true);\n };\n\n const Placeholder = ({\n failed,\n children,\n }: PlaceholderProps) => PlaceholderComponent ? (\n <PlaceholderComponent\n children={children}\n failed={failed}\n />\n ) : children;\n\n const sourceWithSizeParam = {\n ...source,\n uri: size ? `${source.uri}?size=${size}` : source.uri,\n };\n\n useEffect(() => {\n setFailed(false);\n }, [sourceWithSizeParam.uri]);\n\n return (\n <View\n style={css([\n styles.root,\n !disableOutline ? styles.outlined : undefined,\n !disablePlaceholder ? styles.placeholder : undefined,\n !square ? styles.rounded : undefined,\n style,\n ])}\n {...otherProps}\n >\n <Placeholder failed={failed}>\n {!failed ? (\n <React.Fragment>\n <ImageCore\n alt={alt}\n disableDrag={disableDrag}\n disableLongClick={disableLongClick}\n height={'100%'}\n loading={loading}\n onError={handleError}\n onLoad={onLoad}\n resizeMode={resizeMode}\n source={sourceWithSizeParam}\n width={'100%'}\n />\n\n {overlaidChildren ? (\n <View style={StyleSheet.absoluteFill}>\n {overlaidChildren}\n </View>\n ) : null}\n </React.Fragment>\n ) : null}\n </Placeholder>\n </View>\n );\n};\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactNode;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n size?: 'small' | 'medium' | 'large';\n}> {}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\nexport interface PlaceholderProps {\n failed: boolean;\n children: React.ReactElement | null;\n}\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * Disable drag event for web.\n * @default false\n */\n disableDrag?: boolean,\n\n /**\n * Disable Long click event for web.\n * @default false\n */\n disableLongClick?: boolean,\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactNode;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n /**\n * Image file size.\n * Request image by query string.\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * The Custom image placeholder component with condition.\n */\n Placeholder?: (props: PlaceholderProps) => JSX.Element | null;\n}> {}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';"],"mappings":";;;;;;;;;;;;AAAA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';\nexport type { PlaceholderProps } from './ImageProps';"],"mappings":";;;;;;;;;;;;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n disableDrag?: boolean,\n disableLongClick?: boolean,\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
@@ -9,9 +9,19 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
+
const preventDragging = () => false;
|
|
13
|
+
|
|
14
|
+
const preventMouseDown = event => {
|
|
15
|
+
if (event.preventDefault) {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
12
20
|
function ImageCore(props) {
|
|
13
21
|
const {
|
|
14
22
|
alt,
|
|
23
|
+
disableDrag = false,
|
|
24
|
+
disableLongClick = false,
|
|
15
25
|
height,
|
|
16
26
|
loading,
|
|
17
27
|
onError,
|
|
@@ -20,13 +30,20 @@ function ImageCore(props) {
|
|
|
20
30
|
source,
|
|
21
31
|
width
|
|
22
32
|
} = props;
|
|
33
|
+
const disableLongClickStyle = disableLongClick ? {
|
|
34
|
+
'-webkit-user-select': 'none',
|
|
35
|
+
'-webkit-touch-callout': 'none'
|
|
36
|
+
} : {};
|
|
23
37
|
const style = {
|
|
24
|
-
objectFit: resizeMode
|
|
38
|
+
objectFit: resizeMode,
|
|
39
|
+
...disableLongClickStyle
|
|
25
40
|
};
|
|
26
41
|
return /*#__PURE__*/_react.default.createElement("img", {
|
|
27
42
|
alt: alt,
|
|
28
43
|
height: height,
|
|
29
44
|
loading: loading,
|
|
45
|
+
onDragStart: disableDrag ? preventDragging : undefined,
|
|
46
|
+
onMouseDown: disableDrag ? preventMouseDown : undefined,
|
|
30
47
|
onError: onError,
|
|
31
48
|
onLoad: onLoad,
|
|
32
49
|
src: source.uri,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ImageCore","props","alt","height","loading","onError","onLoad","resizeMode","source","width","style","objectFit","uri"],"sources":["ImageCoreWeb.tsx"],"sourcesContent":["import React from 'react';\nimport type ImageCoreProps from './ImageCoreProps';\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n alt,\n height,\n loading,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const style = {
|
|
1
|
+
{"version":3,"names":["preventDragging","preventMouseDown","event","preventDefault","ImageCore","props","alt","disableDrag","disableLongClick","height","loading","onError","onLoad","resizeMode","source","width","disableLongClickStyle","style","objectFit","undefined","uri"],"sources":["ImageCoreWeb.tsx"],"sourcesContent":["import React, { MouseEventHandler } from 'react';\nimport type ImageCoreProps from './ImageCoreProps';\n\nconst preventDragging = () => false;\n\nconst preventMouseDown: MouseEventHandler<HTMLImageElement> = (event) => {\n if (event.preventDefault) {\n event.preventDefault();\n }\n};\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n alt,\n disableDrag = false,\n disableLongClick = false,\n height,\n loading,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const disableLongClickStyle = disableLongClick\n ? {\n '-webkit-user-select': 'none',\n '-webkit-touch-callout': 'none',\n }\n : {};\n\n const style = {\n objectFit: resizeMode,\n ...disableLongClickStyle,\n };\n\n return (\n <img\n alt={alt}\n height={height}\n loading={loading}\n onDragStart={disableDrag ? preventDragging : undefined}\n onMouseDown={disableDrag ? preventMouseDown : undefined}\n onError={onError}\n onLoad={onLoad}\n src={source.uri}\n style={style}\n width={width}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;;;AAGA,MAAMA,eAAe,GAAG,MAAM,KAA9B;;AAEA,MAAMC,gBAAqD,GAAIC,KAAD,IAAW;EACrE,IAAIA,KAAK,CAACC,cAAV,EAA0B;IACtBD,KAAK,CAACC,cAAN;EACH;AACJ,CAJD;;AAMe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,GADE;IAEFC,WAAW,GAAG,KAFZ;IAGFC,gBAAgB,GAAG,KAHjB;IAIFC,MAJE;IAKFC,OALE;IAMFC,OANE;IAOFC,MAPE;IAQFC,UARE;IASFC,MATE;IAUFC;EAVE,IAWFV,KAXJ;EAaA,MAAMW,qBAAqB,GAAGR,gBAAgB,GACxC;IACE,uBAAuB,MADzB;IAEE,yBAAyB;EAF3B,CADwC,GAKxC,EALN;EAOA,MAAMS,KAAK,GAAG;IACVC,SAAS,EAAEL,UADD;IAEV,GAAGG;EAFO,CAAd;EAKA,oBACI;IACI,GAAG,EAAEV,GADT;IAEI,MAAM,EAAEG,MAFZ;IAGI,OAAO,EAAEC,OAHb;IAII,WAAW,EAAEH,WAAW,GAAGP,eAAH,GAAqBmB,SAJjD;IAKI,WAAW,EAAEZ,WAAW,GAAGN,gBAAH,GAAsBkB,SALlD;IAMI,OAAO,EAAER,OANb;IAOI,MAAM,EAAEC,MAPZ;IAQI,GAAG,EAAEE,MAAM,CAACM,GARhB;IASI,KAAK,EAAEH,KATX;IAUI,KAAK,EAAEF;EAVX,EADJ;AAcH;;AAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {
|
|
3
|
+
import React, { useEffect } from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
5
|
import ImageCore from '../ImageCore';
|
|
6
6
|
import { css, StyleSheet, useTheme } from '../styles';
|
|
7
7
|
|
|
@@ -27,6 +27,8 @@ const useStyles = function () {
|
|
|
27
27
|
export default function Image(props) {
|
|
28
28
|
const {
|
|
29
29
|
alt,
|
|
30
|
+
disableDrag,
|
|
31
|
+
disableLongClick,
|
|
30
32
|
disableOutline,
|
|
31
33
|
disablePlaceholder,
|
|
32
34
|
loading = 'lazy',
|
|
@@ -38,6 +40,7 @@ export default function Image(props) {
|
|
|
38
40
|
size,
|
|
39
41
|
onLoad,
|
|
40
42
|
onError,
|
|
43
|
+
Placeholder: PlaceholderComponent,
|
|
41
44
|
...otherProps
|
|
42
45
|
} = props;
|
|
43
46
|
const [failed, setFailed] = React.useState(false);
|
|
@@ -51,13 +54,31 @@ export default function Image(props) {
|
|
|
51
54
|
setFailed(true);
|
|
52
55
|
};
|
|
53
56
|
|
|
57
|
+
const Placeholder = _ref => {
|
|
58
|
+
let {
|
|
59
|
+
failed,
|
|
60
|
+
children
|
|
61
|
+
} = _ref;
|
|
62
|
+
return PlaceholderComponent ? /*#__PURE__*/React.createElement(PlaceholderComponent, {
|
|
63
|
+
children: children,
|
|
64
|
+
failed: failed
|
|
65
|
+
}) : children;
|
|
66
|
+
};
|
|
67
|
+
|
|
54
68
|
const sourceWithSizeParam = { ...source,
|
|
55
69
|
uri: size ? `${source.uri}?size=${size}` : source.uri
|
|
56
70
|
};
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
setFailed(false);
|
|
73
|
+
}, [sourceWithSizeParam.uri]);
|
|
57
74
|
return /*#__PURE__*/React.createElement(View, _extends({
|
|
58
75
|
style: css([styles.root, !disableOutline ? styles.outlined : undefined, !disablePlaceholder ? styles.placeholder : undefined, !square ? styles.rounded : undefined, style])
|
|
59
|
-
}, otherProps),
|
|
76
|
+
}, otherProps), /*#__PURE__*/React.createElement(Placeholder, {
|
|
77
|
+
failed: failed
|
|
78
|
+
}, !failed ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ImageCore, {
|
|
60
79
|
alt: alt,
|
|
80
|
+
disableDrag: disableDrag,
|
|
81
|
+
disableLongClick: disableLongClick,
|
|
61
82
|
height: '100%',
|
|
62
83
|
loading: loading,
|
|
63
84
|
onError: handleError,
|
|
@@ -67,7 +88,7 @@ export default function Image(props) {
|
|
|
67
88
|
width: '100%'
|
|
68
89
|
}), overlaidChildren ? /*#__PURE__*/React.createElement(View, {
|
|
69
90
|
style: StyleSheet.absoluteFill
|
|
70
|
-
}, overlaidChildren) : null);
|
|
91
|
+
}, overlaidChildren) : null) : null));
|
|
71
92
|
}
|
|
72
93
|
;
|
|
73
94
|
//# sourceMappingURL=Image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","useEffect","View","ImageCore","css","StyleSheet","useTheme","useStyles","theme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","hairlineWidth","borderStyle","borderColor","Image","props","alt","disableDrag","disableLongClick","disableOutline","disablePlaceholder","loading","overlaidChildren","resizeMode","source","style","square","size","onLoad","onError","Placeholder","PlaceholderComponent","otherProps","failed","setFailed","useState","styles","handleError","children","sourceWithSizeParam","uri","undefined","absoluteFill"],"sources":["Image.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { View } from 'react-native';\nimport type { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport ImageCore from '../ImageCore';\nimport { css, StyleSheet, useTheme } from '../styles';\nimport type ImageProps from './ImageProps';\nimport { PlaceholderProps } from './ImageProps';\n\ntype ImageStyleKeys =\n | 'root'\n | 'rounded'\n | 'placeholder'\n | 'outlined';\n\ntype ImageStyles = NamedStylesStringUnion<ImageStyleKeys>;\n\nconst useStyles: UseStyles<ImageStyles> = function (): ImageStyles {\n const theme = useTheme();\n\n return {\n root: {},\n rounded: {\n borderRadius: theme.shape.roundness,\n overflow: 'hidden',\n },\n placeholder: {\n backgroundColor: theme.palette.paper.grey,\n },\n outlined: {\n borderWidth: StyleSheet.hairlineWidth,\n borderStyle: 'solid',\n borderColor: theme.palette.paper.grey,\n },\n };\n};\n\nexport default function Image(props: ImageProps) {\n const {\n alt,\n disableDrag,\n disableLongClick,\n disableOutline,\n disablePlaceholder,\n loading = 'lazy',\n overlaidChildren,\n resizeMode = 'cover',\n source,\n style,\n square = false,\n size,\n onLoad,\n onError,\n Placeholder: PlaceholderComponent,\n ...otherProps\n } = props;\n\n const [failed, setFailed] = React.useState(false);\n\n const styles = useStyles();\n\n const handleError = () => {\n if (onError) {\n onError();\n }\n\n setFailed(true);\n };\n\n const Placeholder = ({\n failed,\n children,\n }: PlaceholderProps) => PlaceholderComponent ? (\n <PlaceholderComponent\n children={children}\n failed={failed}\n />\n ) : children;\n\n const sourceWithSizeParam = {\n ...source,\n uri: size ? `${source.uri}?size=${size}` : source.uri,\n };\n\n useEffect(() => {\n setFailed(false);\n }, [sourceWithSizeParam.uri]);\n\n return (\n <View\n style={css([\n styles.root,\n !disableOutline ? styles.outlined : undefined,\n !disablePlaceholder ? styles.placeholder : undefined,\n !square ? styles.rounded : undefined,\n style,\n ])}\n {...otherProps}\n >\n <Placeholder failed={failed}>\n {!failed ? (\n <React.Fragment>\n <ImageCore\n alt={alt}\n disableDrag={disableDrag}\n disableLongClick={disableLongClick}\n height={'100%'}\n loading={loading}\n onError={handleError}\n onLoad={onLoad}\n resizeMode={resizeMode}\n source={sourceWithSizeParam}\n width={'100%'}\n />\n\n {overlaidChildren ? (\n <View style={StyleSheet.absoluteFill}>\n {overlaidChildren}\n </View>\n ) : null}\n </React.Fragment>\n ) : null}\n </Placeholder>\n </View>\n );\n};\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactNode;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n size?: 'small' | 'medium' | 'large';\n}> {}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\nexport interface PlaceholderProps {\n failed: boolean;\n children: React.ReactElement | null;\n}\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * Disable drag event for web.\n * @default false\n */\n disableDrag?: boolean,\n\n /**\n * Disable Long click event for web.\n * @default false\n */\n disableLongClick?: boolean,\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactNode;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n /**\n * Image file size.\n * Request image by query string.\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * The Custom image placeholder component with condition.\n */\n Placeholder?: (props: PlaceholderProps) => JSX.Element | null;\n}> {}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';"],"mappings":"AAAA,SAASA,OAAT,QAAwB,SAAxB"}
|
|
1
|
+
{"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';\nexport type { PlaceholderProps } from './ImageProps';"],"mappings":"AAAA,SAASA,OAAT,QAAwB,SAAxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n disableDrag?: boolean,\n disableLongClick?: boolean,\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const preventDragging = () => false;
|
|
4
|
+
|
|
5
|
+
const preventMouseDown = event => {
|
|
6
|
+
if (event.preventDefault) {
|
|
7
|
+
event.preventDefault();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
2
11
|
export default function ImageCore(props) {
|
|
3
12
|
const {
|
|
4
13
|
alt,
|
|
14
|
+
disableDrag = false,
|
|
15
|
+
disableLongClick = false,
|
|
5
16
|
height,
|
|
6
17
|
loading,
|
|
7
18
|
onError,
|
|
@@ -10,13 +21,20 @@ export default function ImageCore(props) {
|
|
|
10
21
|
source,
|
|
11
22
|
width
|
|
12
23
|
} = props;
|
|
24
|
+
const disableLongClickStyle = disableLongClick ? {
|
|
25
|
+
'-webkit-user-select': 'none',
|
|
26
|
+
'-webkit-touch-callout': 'none'
|
|
27
|
+
} : {};
|
|
13
28
|
const style = {
|
|
14
|
-
objectFit: resizeMode
|
|
29
|
+
objectFit: resizeMode,
|
|
30
|
+
...disableLongClickStyle
|
|
15
31
|
};
|
|
16
32
|
return /*#__PURE__*/React.createElement("img", {
|
|
17
33
|
alt: alt,
|
|
18
34
|
height: height,
|
|
19
35
|
loading: loading,
|
|
36
|
+
onDragStart: disableDrag ? preventDragging : undefined,
|
|
37
|
+
onMouseDown: disableDrag ? preventMouseDown : undefined,
|
|
20
38
|
onError: onError,
|
|
21
39
|
onLoad: onLoad,
|
|
22
40
|
src: source.uri,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","ImageCore","props","alt","height","loading","onError","onLoad","resizeMode","source","width","style","objectFit","uri"],"sources":["ImageCoreWeb.tsx"],"sourcesContent":["import React from 'react';\nimport type ImageCoreProps from './ImageCoreProps';\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n alt,\n height,\n loading,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const style = {
|
|
1
|
+
{"version":3,"names":["React","preventDragging","preventMouseDown","event","preventDefault","ImageCore","props","alt","disableDrag","disableLongClick","height","loading","onError","onLoad","resizeMode","source","width","disableLongClickStyle","style","objectFit","undefined","uri"],"sources":["ImageCoreWeb.tsx"],"sourcesContent":["import React, { MouseEventHandler } from 'react';\nimport type ImageCoreProps from './ImageCoreProps';\n\nconst preventDragging = () => false;\n\nconst preventMouseDown: MouseEventHandler<HTMLImageElement> = (event) => {\n if (event.preventDefault) {\n event.preventDefault();\n }\n};\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n alt,\n disableDrag = false,\n disableLongClick = false,\n height,\n loading,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const disableLongClickStyle = disableLongClick\n ? {\n '-webkit-user-select': 'none',\n '-webkit-touch-callout': 'none',\n }\n : {};\n\n const style = {\n objectFit: resizeMode,\n ...disableLongClickStyle,\n };\n\n return (\n <img\n alt={alt}\n height={height}\n loading={loading}\n onDragStart={disableDrag ? preventDragging : undefined}\n onMouseDown={disableDrag ? preventMouseDown : undefined}\n onError={onError}\n onLoad={onLoad}\n src={source.uri}\n style={style}\n width={width}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAyC,OAAzC;;AAGA,MAAMC,eAAe,GAAG,MAAM,KAA9B;;AAEA,MAAMC,gBAAqD,GAAIC,KAAD,IAAW;EACrE,IAAIA,KAAK,CAACC,cAAV,EAA0B;IACtBD,KAAK,CAACC,cAAN;EACH;AACJ,CAJD;;AAMA,eAAe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,GADE;IAEFC,WAAW,GAAG,KAFZ;IAGFC,gBAAgB,GAAG,KAHjB;IAIFC,MAJE;IAKFC,OALE;IAMFC,OANE;IAOFC,MAPE;IAQFC,UARE;IASFC,MATE;IAUFC;EAVE,IAWFV,KAXJ;EAaA,MAAMW,qBAAqB,GAAGR,gBAAgB,GACxC;IACE,uBAAuB,MADzB;IAEE,yBAAyB;EAF3B,CADwC,GAKxC,EALN;EAOA,MAAMS,KAAK,GAAG;IACVC,SAAS,EAAEL,UADD;IAEV,GAAGG;EAFO,CAAd;EAKA,oBACI;IACI,GAAG,EAAEV,GADT;IAEI,MAAM,EAAEG,MAFZ;IAGI,OAAO,EAAEC,OAHb;IAII,WAAW,EAAEH,WAAW,GAAGP,eAAH,GAAqBmB,SAJjD;IAKI,WAAW,EAAEZ,WAAW,GAAGN,gBAAH,GAAsBkB,SALlD;IAMI,OAAO,EAAER,OANb;IAOI,MAAM,EAAEC,MAPZ;IAQI,GAAG,EAAEE,MAAM,CAACM,GARhB;IASI,KAAK,EAAEH,KATX;IAUI,KAAK,EAAEF;EAVX,EADJ;AAcH;AAAA"}
|
|
@@ -2,12 +2,26 @@ import React from 'react';
|
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import type { OverridableComponentProps } from '../types';
|
|
4
4
|
import type { ImageSource, Loading, ResizeMode } from '../ImageCore';
|
|
5
|
+
export interface PlaceholderProps {
|
|
6
|
+
failed: boolean;
|
|
7
|
+
children: React.ReactElement | null;
|
|
8
|
+
}
|
|
5
9
|
export default interface ImageProps extends OverridableComponentProps<ViewProps, {
|
|
6
10
|
/**
|
|
7
11
|
* Indicating the alternate fallback content to be displayed
|
|
8
12
|
* if the image has not been loaded.
|
|
9
13
|
*/
|
|
10
14
|
alt?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Disable drag event for web.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
disableDrag?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Disable Long click event for web.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disableLongClick?: boolean;
|
|
11
25
|
/**
|
|
12
26
|
* If `true`, the image outline is not rendered.
|
|
13
27
|
* @default false
|
|
@@ -51,6 +65,14 @@ export default interface ImageProps extends OverridableComponentProps<ViewProps,
|
|
|
51
65
|
* @default false
|
|
52
66
|
*/
|
|
53
67
|
square?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Image file size.
|
|
70
|
+
* Request image by query string.
|
|
71
|
+
*/
|
|
54
72
|
size?: 'small' | 'medium' | 'large';
|
|
73
|
+
/**
|
|
74
|
+
* The Custom image placeholder component with condition.
|
|
75
|
+
*/
|
|
76
|
+
Placeholder?: (props: PlaceholderProps) => JSX.Element | null;
|
|
55
77
|
}> {
|
|
56
78
|
}
|
|
@@ -5,6 +5,8 @@ export declare type ResizeMode = 'cover' | 'contain';
|
|
|
5
5
|
export declare type Loading = 'lazy' | 'eager';
|
|
6
6
|
export default interface ImageCoreProps extends Readonly<{
|
|
7
7
|
alt?: string;
|
|
8
|
+
disableDrag?: boolean;
|
|
9
|
+
disableLongClick?: boolean;
|
|
8
10
|
height?: number | string;
|
|
9
11
|
loading: Loading;
|
|
10
12
|
onError?: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fountain-ui/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.38",
|
|
4
4
|
"author": "Fountain-UI Team",
|
|
5
5
|
"description": "React components that implement Tappytoon's Fountain Design.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "c967fb1d7418883204e42ee037f2969107bcbaa6"
|
|
71
71
|
}
|
package/src/Image/Image.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
import type { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
|
|
4
4
|
import ImageCore from '../ImageCore';
|
|
5
5
|
import { css, StyleSheet, useTheme } from '../styles';
|
|
6
6
|
import type ImageProps from './ImageProps';
|
|
7
|
+
import { PlaceholderProps } from './ImageProps';
|
|
7
8
|
|
|
8
9
|
type ImageStyleKeys =
|
|
9
10
|
| 'root'
|
|
@@ -36,6 +37,8 @@ const useStyles: UseStyles<ImageStyles> = function (): ImageStyles {
|
|
|
36
37
|
export default function Image(props: ImageProps) {
|
|
37
38
|
const {
|
|
38
39
|
alt,
|
|
40
|
+
disableDrag,
|
|
41
|
+
disableLongClick,
|
|
39
42
|
disableOutline,
|
|
40
43
|
disablePlaceholder,
|
|
41
44
|
loading = 'lazy',
|
|
@@ -47,6 +50,7 @@ export default function Image(props: ImageProps) {
|
|
|
47
50
|
size,
|
|
48
51
|
onLoad,
|
|
49
52
|
onError,
|
|
53
|
+
Placeholder: PlaceholderComponent,
|
|
50
54
|
...otherProps
|
|
51
55
|
} = props;
|
|
52
56
|
|
|
@@ -55,18 +59,32 @@ export default function Image(props: ImageProps) {
|
|
|
55
59
|
const styles = useStyles();
|
|
56
60
|
|
|
57
61
|
const handleError = () => {
|
|
58
|
-
if(onError){
|
|
62
|
+
if (onError) {
|
|
59
63
|
onError();
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
setFailed(true);
|
|
63
|
-
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const Placeholder = ({
|
|
70
|
+
failed,
|
|
71
|
+
children,
|
|
72
|
+
}: PlaceholderProps) => PlaceholderComponent ? (
|
|
73
|
+
<PlaceholderComponent
|
|
74
|
+
children={children}
|
|
75
|
+
failed={failed}
|
|
76
|
+
/>
|
|
77
|
+
) : children;
|
|
64
78
|
|
|
65
79
|
const sourceWithSizeParam = {
|
|
66
80
|
...source,
|
|
67
81
|
uri: size ? `${source.uri}?size=${size}` : source.uri,
|
|
68
82
|
};
|
|
69
83
|
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setFailed(false);
|
|
86
|
+
}, [sourceWithSizeParam.uri]);
|
|
87
|
+
|
|
70
88
|
return (
|
|
71
89
|
<View
|
|
72
90
|
style={css([
|
|
@@ -78,26 +96,30 @@ export default function Image(props: ImageProps) {
|
|
|
78
96
|
])}
|
|
79
97
|
{...otherProps}
|
|
80
98
|
>
|
|
81
|
-
{failed
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
<Placeholder failed={failed}>
|
|
100
|
+
{!failed ? (
|
|
101
|
+
<React.Fragment>
|
|
102
|
+
<ImageCore
|
|
103
|
+
alt={alt}
|
|
104
|
+
disableDrag={disableDrag}
|
|
105
|
+
disableLongClick={disableLongClick}
|
|
106
|
+
height={'100%'}
|
|
107
|
+
loading={loading}
|
|
108
|
+
onError={handleError}
|
|
109
|
+
onLoad={onLoad}
|
|
110
|
+
resizeMode={resizeMode}
|
|
111
|
+
source={sourceWithSizeParam}
|
|
112
|
+
width={'100%'}
|
|
113
|
+
/>
|
|
95
114
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
{overlaidChildren ? (
|
|
116
|
+
<View style={StyleSheet.absoluteFill}>
|
|
117
|
+
{overlaidChildren}
|
|
118
|
+
</View>
|
|
119
|
+
) : null}
|
|
120
|
+
</React.Fragment>
|
|
121
|
+
) : null}
|
|
122
|
+
</Placeholder>
|
|
101
123
|
</View>
|
|
102
124
|
);
|
|
103
125
|
};
|
package/src/Image/ImageProps.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { ViewProps } from 'react-native';
|
|
|
3
3
|
import type { OverridableComponentProps } from '../types';
|
|
4
4
|
import type { ImageSource, Loading, ResizeMode } from '../ImageCore';
|
|
5
5
|
|
|
6
|
+
export interface PlaceholderProps {
|
|
7
|
+
failed: boolean;
|
|
8
|
+
children: React.ReactElement | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export default interface ImageProps extends OverridableComponentProps<ViewProps, {
|
|
7
12
|
/**
|
|
8
13
|
* Indicating the alternate fallback content to be displayed
|
|
@@ -10,6 +15,18 @@ export default interface ImageProps extends OverridableComponentProps<ViewProps,
|
|
|
10
15
|
*/
|
|
11
16
|
alt?: string;
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Disable drag event for web.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
disableDrag?: boolean,
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Disable Long click event for web.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
disableLongClick?: boolean,
|
|
29
|
+
|
|
13
30
|
/**
|
|
14
31
|
* If `true`, the image outline is not rendered.
|
|
15
32
|
* @default false
|
|
@@ -62,5 +79,14 @@ export default interface ImageProps extends OverridableComponentProps<ViewProps,
|
|
|
62
79
|
*/
|
|
63
80
|
square?: boolean;
|
|
64
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Image file size.
|
|
84
|
+
* Request image by query string.
|
|
85
|
+
*/
|
|
65
86
|
size?: 'small' | 'medium' | 'large';
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The Custom image placeholder component with condition.
|
|
90
|
+
*/
|
|
91
|
+
Placeholder?: (props: PlaceholderProps) => JSX.Element | null;
|
|
66
92
|
}> {}
|
package/src/Image/index.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { MouseEventHandler } from 'react';
|
|
2
2
|
import type ImageCoreProps from './ImageCoreProps';
|
|
3
3
|
|
|
4
|
+
const preventDragging = () => false;
|
|
5
|
+
|
|
6
|
+
const preventMouseDown: MouseEventHandler<HTMLImageElement> = (event) => {
|
|
7
|
+
if (event.preventDefault) {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
4
12
|
export default function ImageCore(props: ImageCoreProps) {
|
|
5
13
|
const {
|
|
6
14
|
alt,
|
|
15
|
+
disableDrag = false,
|
|
16
|
+
disableLongClick = false,
|
|
7
17
|
height,
|
|
8
18
|
loading,
|
|
9
19
|
onError,
|
|
@@ -13,13 +23,25 @@ export default function ImageCore(props: ImageCoreProps) {
|
|
|
13
23
|
width,
|
|
14
24
|
} = props;
|
|
15
25
|
|
|
16
|
-
const
|
|
26
|
+
const disableLongClickStyle = disableLongClick
|
|
27
|
+
? {
|
|
28
|
+
'-webkit-user-select': 'none',
|
|
29
|
+
'-webkit-touch-callout': 'none',
|
|
30
|
+
}
|
|
31
|
+
: {};
|
|
32
|
+
|
|
33
|
+
const style = {
|
|
34
|
+
objectFit: resizeMode,
|
|
35
|
+
...disableLongClickStyle,
|
|
36
|
+
};
|
|
17
37
|
|
|
18
38
|
return (
|
|
19
39
|
<img
|
|
20
40
|
alt={alt}
|
|
21
41
|
height={height}
|
|
22
42
|
loading={loading}
|
|
43
|
+
onDragStart={disableDrag ? preventDragging : undefined}
|
|
44
|
+
onMouseDown={disableDrag ? preventMouseDown : undefined}
|
|
23
45
|
onError={onError}
|
|
24
46
|
onLoad={onLoad}
|
|
25
47
|
src={source.uri}
|