@theoplayer/react-native-ui
Version:
A React Native UI for @theoplayer/react-native
85 lines (83 loc) • 3.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DEFAULT_ACTION_BUTTON_STYLE = exports.ActionButton = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _SvgUtils = require("../svg/SvgUtils");
var _PlayerContext = require("../../util/PlayerContext");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
* The default style applied to the ActionButton
*/
const DEFAULT_ACTION_BUTTON_STYLE = exports.DEFAULT_ACTION_BUTTON_STYLE = {
height: '100%',
aspectRatio: 1,
padding: 5
};
/**
* The default button component that renders an image/svg source for the `react-native-theoplayer` UI.
*/
const ActionButton = props => {
const {
activeOpacity,
children,
icon,
style,
svg,
onPress,
highlighted,
testID
} = props;
const [focused, setFocused] = (0, _react.useState)(false);
const context = (0, _react.useContext)(_PlayerContext.PlayerContext);
const shouldChangeTintColor = highlighted || focused && _reactNative.Platform.isTV;
const touchable = props.touchable != false;
if (!touchable) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [DEFAULT_ACTION_BUTTON_STYLE, style],
children: svg
});
}
const onTouch = () => {
if (context.ui.buttonsEnabled_) {
onPress?.();
}
context.ui.onUserAction_();
};
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
style: [DEFAULT_ACTION_BUTTON_STYLE, style],
testID: testID,
activeOpacity: activeOpacity,
onPress: onTouch,
onFocus: () => {
context.ui.onUserAction_();
setFocused(true);
},
onBlur: () => {
setFocused(false);
},
children: [svg && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgUtils.SvgContext.Provider, {
value: {
fill: shouldChangeTintColor ? context.style.colors.iconSelected : context.style.colors.icon,
height: '100%',
width: '100%'
},
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
children: svg
})
}), svg === undefined && icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
style: [{
height: '100%',
width: '100%'
}, {
tintColor: shouldChangeTintColor ? context.style.colors.iconSelected : context.style.colors.icon
}],
source: icon
}), children]
});
};
exports.ActionButton = ActionButton;
//# sourceMappingURL=ActionButton.js.map