@expo/react-native-action-sheet
Version:
A cross-platform ActionSheet for React Native
2 lines • 7.36 kB
JavaScript
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _inherits from"@babel/runtime/helpers/inherits";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";var _jsxFileName="/home/runner/work/react-native-action-sheet/react-native-action-sheet/src/ActionSheet/ActionGroup.tsx";function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return true;}catch(e){return false;}}import*as React from'react';import{AccessibilityInfo,findNodeHandle,Image,Platform,ScrollView,StyleSheet,Text,UIManager,View}from'react-native';import TouchableNativeFeedbackSafe from'./TouchableNativeFeedbackSafe';var BLACK_54PC_TRANSPARENT='#0000008a';var BLACK_87PC_TRANSPARENT='#000000de';var DESTRUCTIVE_COLOR='#d32f2f';var focusViewOnRender=function focusViewOnRender(ref){if(ref){var reactTag=findNodeHandle(ref);if(reactTag){if(Platform.OS==='android'){UIManager.sendAccessibilityEvent(reactTag,UIManager.AccessibilityEventTypes.typeViewFocused);}else{AccessibilityInfo.setAccessibilityFocus(reactTag);}}}};var isIndexDestructive=function isIndexDestructive(index,destructiveIndex){if(Array.isArray(destructiveIndex)){return destructiveIndex.includes(index);}return index===destructiveIndex;};var isIndexDisabled=function isIndexDisabled(index){var disabledButtonIndices=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];return disabledButtonIndices.includes(index);};var ActionGroup=function(_React$Component){_inherits(ActionGroup,_React$Component);var _super=_createSuper(ActionGroup);function ActionGroup(){var _this;_classCallCheck(this,ActionGroup);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_this._renderRowSeparator=function(key){return React.createElement(View,{key:"separator-"+key,style:[styles.rowSeparator,_this.props.separatorStyle],__source:{fileName:_jsxFileName,lineNumber:82,columnNumber:7}});};_this._renderTitleContent=function(){var _this$props=_this.props,title=_this$props.title,titleTextStyle=_this$props.titleTextStyle,message=_this$props.message,messageTextStyle=_this$props.messageTextStyle,showSeparators=_this$props.showSeparators;if(!title&&!message){return null;}return React.createElement(View,{__source:{fileName:_jsxFileName,lineNumber:94,columnNumber:7}},React.createElement(View,{style:[styles.titleContainer,{paddingBottom:showSeparators?24:16}],__source:{fileName:_jsxFileName,lineNumber:95,columnNumber:9}},!!title&&React.createElement(Text,{style:[styles.title,titleTextStyle],__source:{fileName:_jsxFileName,lineNumber:96,columnNumber:23}},title),!!message&&React.createElement(Text,{style:[styles.message,messageTextStyle],__source:{fileName:_jsxFileName,lineNumber:97,columnNumber:25}},message)),!!showSeparators&&_this._renderRowSeparator('title'));};_this._renderIconElement=function(iconSource,color){var tintIcons=_this.props.tintIcons;if(!iconSource){return null;}if(typeof iconSource==='number'){var iconStyle=[styles.icon,{tintColor:tintIcons?color:undefined}];return React.createElement(Image,{fadeDuration:0,source:iconSource,resizeMode:"contain",style:iconStyle,__source:{fileName:_jsxFileName,lineNumber:112,columnNumber:14}});}else{return React.createElement(View,{style:styles.icon,__source:{fileName:_jsxFileName,lineNumber:114,columnNumber:14}},iconSource);}};_this._renderOptionViews=function(){var _this$props2=_this.props,options=_this$props2.options,icons=_this$props2.icons,cancelButtonIndex=_this$props2.cancelButtonIndex,cancelButtonTintColor=_this$props2.cancelButtonTintColor,destructiveButtonIndex=_this$props2.destructiveButtonIndex,disabledButtonIndices=_this$props2.disabledButtonIndices,_this$props2$destruct=_this$props2.destructiveColor,destructiveColor=_this$props2$destruct===void 0?DESTRUCTIVE_COLOR:_this$props2$destruct,onSelect=_this$props2.onSelect,startIndex=_this$props2.startIndex,length=_this$props2.length,textStyle=_this$props2.textStyle,tintColor=_this$props2.tintColor,autoFocus=_this$props2.autoFocus,showSeparators=_this$props2.showSeparators;var optionViews=[];var nativeFeedbackBackground=TouchableNativeFeedbackSafe.Ripple('rgba(180, 180, 180, 1)',false);var _loop=function _loop(_i){var defaultColor=tintColor?tintColor:(textStyle||{}).color||BLACK_87PC_TRANSPARENT;var disabled=isIndexDisabled(_i,disabledButtonIndices);var isCancelButton=_i===cancelButtonIndex;var color=isIndexDestructive(_i,destructiveButtonIndex)?destructiveColor:isCancelButton?cancelButtonTintColor||defaultColor:defaultColor;var iconSource=icons!=null?icons[_i]:null;optionViews.push(React.createElement(TouchableNativeFeedbackSafe,{ref:autoFocus&&_i===0?focusViewOnRender:undefined,key:_i,pressInDelay:0,background:nativeFeedbackBackground,disabled:disabled,onPress:function onPress(){return onSelect(_i);},style:[styles.button,disabled&&styles.disabledButton],accessibilityRole:"button",accessibilityLabel:options[_i],__source:{fileName:_jsxFileName,lineNumber:155,columnNumber:9}},_this._renderIconElement(iconSource,color),React.createElement(Text,{style:[styles.text,textStyle,{color:color}],__source:{fileName:_jsxFileName,lineNumber:166,columnNumber:11}},options[_i])));if(showSeparators&&_i<startIndex+length-1){optionViews.push(_this._renderRowSeparator(_i));}};for(var _i=startIndex;_i<startIndex+length;_i++){_loop(_i);}return optionViews;};return _this;}_createClass(ActionGroup,[{key:"render",value:function render(){return React.createElement(View,{style:[styles.groupContainer,this.props.containerStyle],__source:{fileName:_jsxFileName,lineNumber:73,columnNumber:7}},this._renderTitleContent(),React.createElement(ScrollView,{__source:{fileName:_jsxFileName,lineNumber:75,columnNumber:9}},this._renderOptionViews()));}}]);return ActionGroup;}(React.Component);ActionGroup.defaultProps={title:null,message:null,showSeparators:false,tintIcons:true,textStyle:{}};export{ActionGroup as default};var styles=StyleSheet.create({button:{justifyContent:'flex-start',alignItems:'center',flexDirection:'row',height:56,paddingHorizontal:16},disabledButton:{opacity:0.5},groupContainer:{backgroundColor:'#ffffff',overflow:'hidden'},icon:{width:24,height:24,marginRight:32,justifyContent:'center'},message:{marginTop:12,fontSize:14,color:BLACK_54PC_TRANSPARENT,textAlignVertical:'center'},rowSeparator:{backgroundColor:'#dddddd',height:1,width:'100%'},text:{fontSize:16,color:BLACK_87PC_TRANSPARENT,textAlignVertical:'center'},title:{fontSize:16,color:BLACK_54PC_TRANSPARENT,textAlignVertical:'center'},titleContainer:{alignItems:'flex-start',padding:16,paddingTop:24}});
//# sourceMappingURL=ActionGroup.js.map