@hyext-beyond/hy-ui-native
Version:
A native lib polyfill for huya miniapp
130 lines (127 loc) • 6.82 kB
JavaScript
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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); }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
/*
* A smart image loader for react-native apps
* https://github.com/react-native-component/react-native-smart-image-loader/
* Released under the MIT license
* Copyright (c) 2016 react-native-component <moonsunfall@aliyun.com>
*/
import React, { Component } from 'react';
import ReactNative, { View, requireNativeComponent, UIManager } from 'react-native';
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
var AssetRegistry = require('react-native/Libraries/Image/AssetRegistry');
var PropTypes = process.env.NODE_ENV !== "production" ? require('prop-types') : {};
import { __DEV__ } from '../../common/env';
import { contentModeMap } from "./contentMode";
export var NativeImage = /*#__PURE__*/function (_Component) {
_inheritsLoose(NativeImage, _Component);
function NativeImage(props) {
var _this;
_this = _Component.call(this, props) || this;
_this.state = {};
return _this;
}
var _proto = NativeImage.prototype;
_proto.componentDidMount = function componentDidMount() {
if (this.props.onRef) {
this.props.onRef(this);
}
};
_proto.stopAnimation = function stopAnimation() {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(this), UIManager.getViewManagerConfig('HYRNTImageView').Commands.stopAnimation, null);
};
_proto.startAnimation = function startAnimation() {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(this), UIManager.getViewManagerConfig('HYRNTImageView').Commands.startAnimation, null);
};
_proto.render = function render() {
var _this2 = this;
var imgUrl = "";
if (__DEV__) {
var base64ID = this.props.source.base64;
if (Number.isInteger(base64ID)) {
imgUrl = resolveAssetSource(base64ID).uri;
}
}
//DEV source={require('image')}
if (typeof this.props.source == 'number') {
imgUrl = resolveAssetSource(this.props.source).uri;
}
//RELEASE source={{uri: 'http://xxx'}}
else if (typeof this.props.source == 'object' && this.props.source.uri) {
imgUrl = this.props.source.uri;
}
//RELEASE source={'http://xxx'}
else {}
var originalAsset = __DEV__ ? undefined : AssetRegistry.getAssetByID(this.props.source.base64);
var mode = this.props.mode || 'stretch';
var contentMode = contentModeMap[mode];
return /*#__PURE__*/React.createElement(NativeImageLoader, _extends({}, this.props, {
source: {
uri: imgUrl || "",
uris: this.props.source.uris,
repeat: this.props.source.repeat,
duration: this.props.source.duration,
animated: this.props.source.animated,
placeholder: this.props.source.placeholder,
base64: originalAsset !== undefined ? originalAsset.base64 : undefined,
autoPlay: this.props.source.autoPlay == null ? true : this.props.source.autoPlay
},
contentMode: contentMode,
onDownloadSuccess: function onDownloadSuccess(params) {
_this2.props.onDownloadSuccess && _this2.props.onDownloadSuccess(params);
},
onDownloadFailed: function onDownloadFailed(err) {
_this2.props.onDownloadFailed && _this2.props.onDownloadFailed(err);
},
onPlayComplete: function onPlayComplete() {
_this2.props.onPlayComplete && _this2.props.onPlayComplete();
},
onPlayFailed: function onPlayFailed() {
_this2.props.onPlayFailed && _this2.props.onPlayFailed();
}
}));
};
return NativeImage;
}(Component);
NativeImage.propTypes = process.env.NODE_ENV !== "production" ? _objectSpread(_objectSpread({}, View.propTypes), {}, {
options: PropTypes.shape({
src: PropTypes.string,
placeholder: PropTypes.string
}),
loopCount: PropTypes.number,
source: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
uri: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
uris: PropTypes.array,
repeat: PropTypes.bool,
duration: PropTypes.number,
animated: PropTypes.bool,
placeholder: PropTypes.string,
autoPlay: PropTypes.bool,
base64: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
})]),
fadeDuration: PropTypes.number,
resizeMethod: PropTypes.oneOf(['auto', 'resize', 'scale']),
progressiveRenderingEnabled: PropTypes.bool,
blurRadius: PropTypes.number,
onDownloadSuccess: PropTypes.func,
onDownloadFailed: PropTypes.func,
onPlayComplete: PropTypes.func,
onPlayFailed: PropTypes.func
}) : {};
var cfg = {
nativeOnly: {
src: true,
headers: true,
loadingIndicatorSrc: true,
shouldNotifyLoadEvents: true
}
};
// @ts-ignore
var NativeImageLoader = requireNativeComponent('HYRNTImageView', NativeImage, cfg);
export default NativeImage;