rax-image
Advanced tools
Comparing version 1.1.3 to 2.0.1
@@ -1,4 +0,3 @@ | ||
import { ForwardRefExoticComponent } from 'rax'; | ||
import { ImageProps } from './types'; | ||
declare const Image: ForwardRefExoticComponent<ImageProps>; | ||
declare function Image(props: ImageProps): JSX.Element; | ||
export default Image; |
@@ -12,16 +12,3 @@ "use strict"; | ||
var __rest = void 0 && (void 0).__rest || function (s, e) { | ||
var t = {}; | ||
for (var p in s) { | ||
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; | ||
} | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var Image = (0, _rax.forwardRef)(function (props, ref) { | ||
function Image(props) { | ||
var _useState = (0, _rax.useState)(props.source), | ||
@@ -31,5 +18,3 @@ source = _useState[0], | ||
var isInitialMount = (0, _rax.useRef)(false); | ||
var onError = function (e) { | ||
var onError = (0, _rax.useCallback)(function (e) { | ||
var fallbackSource = props.fallbackSource, | ||
@@ -44,5 +29,4 @@ _props$onError = props.onError, | ||
onError(e); | ||
}; | ||
var onLoad = function (e) { | ||
}, []); | ||
var onLoad = (0, _rax.useCallback)(function (e) { | ||
var _props$onLoad = props.onLoad, | ||
@@ -64,19 +48,15 @@ onLoad = _props$onLoad === void 0 ? function () {} : _props$onLoad; | ||
} | ||
}; | ||
}, []); // Source must a object | ||
(0, _rax.useEffect)(function () { | ||
if (!isInitialMount.current) { | ||
isInitialMount.current = true; | ||
} else { | ||
setSource(props.source); | ||
} | ||
}, [props.source.uri]); | ||
var nativeProps = Object.assign({}, props); // Source must a object | ||
if (source && source.uri) { | ||
var _nativeProps$style = nativeProps.style, | ||
style = _nativeProps$style === void 0 ? {} : _nativeProps$style; | ||
var _props$style = props.style, | ||
style = _props$style === void 0 ? {} : _props$style; | ||
var width = source.width, | ||
height = source.height, | ||
uri = source.uri; | ||
var nativeProps = Object.assign(Object.assign({}, props), { | ||
src: uri, | ||
onLoad: onLoad, | ||
onError: onError | ||
}); | ||
nativeProps.style = Object.assign({ | ||
@@ -86,5 +66,2 @@ width: width, | ||
}, style); | ||
nativeProps.src = uri; | ||
nativeProps.onLoad = onLoad; | ||
nativeProps.onError = onError; | ||
delete nativeProps.source; // for cover and contain | ||
@@ -101,24 +78,14 @@ | ||
} | ||
} | ||
} // Set default quality to "original" in weex avoid image be optimized unexpect | ||
var className = nativeProps.className, | ||
children = nativeProps.children, | ||
nativeStyle = nativeProps.style, | ||
otherProps = __rest(nativeProps, ["className", "children", "style"]); | ||
var cls = ['rax-image', className].join(' '); | ||
return _universalEnv.isWeex ? (0, _rax.createElement)("image", _extends({ | ||
ref: ref, | ||
className: cls, | ||
style: nativeStyle | ||
}, otherProps)) : (0, _rax.createElement)("img", _extends({ | ||
ref: ref, | ||
className: cls, | ||
style: nativeStyle | ||
}, otherProps)); | ||
quality: "original" | ||
}, nativeProps)) : (0, _rax.createElement)("img", nativeProps); | ||
} | ||
return null; | ||
}); | ||
} | ||
var _default = Image; | ||
exports.default = _default; |
{ | ||
"component": true | ||
"component": true | ||
} |
@@ -58,1 +58,5 @@ import { HTMLAttributes, RefAttributes, CSSProperties, SyntheticEvent } from 'rax'; | ||
} | ||
export interface ImageNativeProps extends ImageProps { | ||
src: string; | ||
resize?: string; | ||
} |
{ | ||
"name": "rax-image", | ||
"version": "1.1.3", | ||
"version": "2.0.1", | ||
"description": "Image component for Rax.", | ||
@@ -37,3 +37,3 @@ "license": "BSD-3-Clause", | ||
"dependencies": { | ||
"universal-env": "^1.0.0" | ||
"universal-env": "^3.0.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "peerDependencies": { |
{ | ||
"component": true | ||
"component": true | ||
} |
@@ -17,5 +17,3 @@ import { | ||
*/ | ||
export interface ImageProps | ||
extends HTMLAttributes<HTMLImageElement>, | ||
RefAttributes<HTMLImageElement> { | ||
export interface ImageProps extends HTMLAttributes<HTMLImageElement>, RefAttributes<HTMLImageElement> { | ||
/** | ||
@@ -69,1 +67,6 @@ * source: set image uri | ||
} | ||
export interface ImageNativeProps extends ImageProps { | ||
src: string; | ||
resize?: string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31054
654
+ Added@uni/env@1.1.1(transitive)
+ Addeduniversal-env@3.3.3(transitive)
- Removeduniversal-env@1.0.7(transitive)
Updateduniversal-env@^3.0.0