react-web-native-sketch
Version:
[TODO: We need an overview of how this can be used via npm vs as a local package]
131 lines • 6.18 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var redux_1 = require("redux");
var react_native_1 = require("react-native");
var react_redux_1 = require("react-redux");
var __1 = require("../");
var hoist_non_react_statics_1 = require("../lib/hoist-non-react-statics");
var platform_1 = require("../primitives/platform/platform");
var dialog_1 = require("../redux/reducers/dialog");
var theme_1 = require("./theme");
function connectActionSheet(WrappedComponent) {
if (platform_1.isIOS) {
return connectActionSheetIos(WrappedComponent);
}
return connectActionSheetAndroid(WrappedComponent);
}
exports.connectActionSheet = connectActionSheet;
function connectActionSheetAndroid(WrappedComponent) {
var styles = function () {
var _a;
return ({
dialog: {
width: '100%',
height: '100%',
backgroundColor: 'rgba(0,0,0,0.4)',
justifyContent: 'center',
alignItems: 'center',
},
dataContainer: {
width: '80%',
borderRadius: (_a = {},
_a[theme_1.ios] = 14,
_a[theme_1.android] = 4,
_a),
backgroundColor: 'rgb(255,255,255)',
flexDirection: 'column',
}
});
};
var CEnhance = /** @class */ (function (_super) {
__extends(CEnhance, _super);
function CEnhance(props) {
var _this = _super.call(this, props) || this;
_this.onClose = function () {
props.showActionSheet(_this.state.sheetId, false);
_this.setState({ visible: false });
};
_this.state = {
visible: false,
sheetId: undefined,
};
return _this;
}
CEnhance.prototype.render = function () {
var _this = this;
var _a = this.props, classes = _a.classes, showActionSheet = _a.showActionSheet, _b = this.state, visible = _b.visible, sheetId = _b.sheetId;
var sheetData = undefined;
if (sheetId) {
sheetData = WrappedComponent.actionSheetData(this.props)[sheetId];
}
return (React.createElement(__1.View, null,
React.createElement(WrappedComponent, __assign({}, this.props, { connectedShowActionSheet: function (sheetId) {
showActionSheet(sheetId);
_this.setState({ sheetId: sheetId, visible: true });
} })),
sheetId &&
React.createElement(react_native_1.Modal, { transparent: true, visible: visible, onRequestClose: this.onClose, animationType: 'fade' },
React.createElement(__1.View, { style: classes.dialog },
React.createElement(__1.View, { style: classes.dataContainer }, sheetData && sheetData.options.map(function (option, index) {
return React.createElement(__1.Button, { title: option, onPress: function () {
_this.onClose();
sheetData && sheetData.optionClick(index);
} });
}))))));
};
return CEnhance;
}(React.PureComponent));
var Enhance = redux_1.compose(react_redux_1.connect(null, { showActionSheet: dialog_1.showActionSheet }), __1.createStyles(styles, 'EnhanceSheet'))(CEnhance);
// need this for statics like react-native-navigation navigatorStyle/ navigatorButtons
hoist_non_react_statics_1.hoistNonReactStatics(Enhance, WrappedComponent, null);
return Enhance;
}
function connectActionSheetIos(WrappedComponent) {
var CEnhance = /** @class */ (function (_super) {
__extends(CEnhance, _super);
function CEnhance() {
return _super !== null && _super.apply(this, arguments) || this;
}
CEnhance.prototype.render = function () {
var _this = this;
var showActionSheet = this.props.showActionSheet;
return (React.createElement(WrappedComponent, __assign({}, this.props, { connectedShowActionSheet: function (sheetId) {
showActionSheet(sheetId);
var sheetData = WrappedComponent.actionSheetData(_this.props)[sheetId];
react_native_1.ActionSheetIOS.showActionSheetWithOptions({
options: sheetData.options,
cancelButtonIndex: sheetData.options.length - 1,
destructiveButtonIndex: -1,
}, function (buttonIndex) {
sheetData.optionClick(buttonIndex);
// Do something here depending on the button index selected
});
} })));
};
return CEnhance;
}(React.PureComponent));
var Enhance = react_redux_1.connect(null, { showActionSheet: dialog_1.showActionSheet })(CEnhance);
// need this for statics like react-native-navigation navigatorStyle/ navigatorButtons
hoist_non_react_statics_1.hoistNonReactStatics(Enhance, WrappedComponent, null);
return Enhance;
}
//# sourceMappingURL=addActionSheet.native.js.map