tuya-panel-kit
Version:
a functional component library for developing tuya device panels!
154 lines (123 loc) • 5.58 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _jsxFileName = 'src/components/layout/offline-view/webview.js';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactNative = require('react-native');
var _TYNativeApi = require('../../../TYNativeApi');
var _webview = require('../../webview');
var _webview2 = _interopRequireDefault(_webview);
var _topbar = require('../topbar');
var _topbar2 = _interopRequireDefault(_topbar);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var OfflineWebView = function (_Component) {
_inherits(OfflineWebView, _Component);
function OfflineWebView() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, OfflineWebView);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = OfflineWebView.__proto__ || Object.getPrototypeOf(OfflineWebView)).call.apply(_ref, [this].concat(args))), _this), _this.onBack = function (tab) {
var navigator = _this.props.navigator;
if (!_this.props.onBack || !_this.props.onBack()) {
if (tab === 'right') {
_TYNativeApi.TYSdk.native.showDeviceMenu();
} else {
if (navigator && navigator.getCurrentRoutes().length > 1) {
navigator.pop();
return true;
}
return false;
}
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(OfflineWebView, [{
key: 'renderTopBar',
value: function renderTopBar() {
var _this2 = this;
var _props = this.props,
title = _props.title,
topBarStyle = _props.topBarStyle,
hideTopbar = _props.hideTopbar,
topbarTextStyle = _props.topbarTextStyle;
if (!hideTopbar) {
var _ref2 = _reactNative.StyleSheet.flatten(topbarTextStyle) || {},
_ref2$color = _ref2.color,
color = _ref2$color === undefined ? '#000' : _ref2$color;
return _react2.default.createElement(_topbar2.default, {
style: topBarStyle,
title: title,
titleStyle: topbarTextStyle,
color: color,
actions: null,
onBack: function onBack() {
return _this2.onBack('left');
},
__source: {
fileName: _jsxFileName,
lineNumber: 50
}
});
}
return null;
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
source = _props2.source,
appStyle = _props2.appStyle,
barStyle = _props2.barStyle;
return _react2.default.createElement(
_reactNative.View,
{ style: [{ flex: 1 }, appStyle], __source: {
fileName: _jsxFileName,
lineNumber: 66
}
},
_react2.default.createElement(_reactNative.StatusBar, { barStyle: barStyle, __source: {
fileName: _jsxFileName,
lineNumber: 67
}
}),
this.renderTopBar(),
_react2.default.createElement(_webview2.default, { source: source, __source: {
fileName: _jsxFileName,
lineNumber: 69
}
})
);
}
}]);
return OfflineWebView;
}(_react.Component);
OfflineWebView.propTypes = {
title: _propTypes2.default.string,
topBarStyle: _reactNative.ViewPropTypes.style,
topbarTextStyle: _reactNative.Text.propTypes.style,
hideTopbar: _propTypes2.default.bool,
onBack: _propTypes2.default.func,
source: _propTypes2.default.string.isRequired,
appStyle: _reactNative.ViewPropTypes.style,
barStyle: _propTypes2.default.string
};
OfflineWebView.defaultProps = {
title: '',
topBarStyle: null,
hideTopbar: false,
onBack: null,
topbarTextStyle: null,
appStyle: null,
barStyle: 'default'
};
exports.default = OfflineWebView;