File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed
example/examples/src/routes/ActionSheet
packages/core/src/ActionSheet Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -41,17 +41,15 @@ export default class Index extends Component<IndexProps, IndexState> {
4141 maskClosable = { true }
4242 dividerStyle = { {
4343 itemDivider : { height : 2 } ,
44- } } >
44+ } }
45+ onCancel = { this . onCancel } >
4546 < ActionSheetItem
4647 onPress = { ( ) => {
4748 Toast . info ( '你点击了按钮一' , 2 , 'info' ) ;
4849 } } >
4950 按钮一
5051 </ ActionSheetItem >
51- < ActionSheetItem
52- onPress = { ( ) => Toast . info ( '你点击了按钮二' , 2 , 'info' ) } >
53- 按钮二
54- </ ActionSheetItem >
52+ < ActionSheetItem onPress = { ( ) => Toast . info ( '你点击了按钮二' , 2 , 'info' ) } > 按钮二</ ActionSheetItem >
5553 < ActionSheetItem onPress = { this . onCancel } > 关闭</ ActionSheetItem >
5654 </ ActionSheet >
5755 </ Body >
Original file line number Diff line number Diff line change @@ -56,13 +56,14 @@ export default Demo
5656
5757| 参数 | 说明 | 类型 | 默认值 |
5858| ------| ------| -----| ------|
59- | onCancel | 点击蒙层是否关闭 | Boolean | ` false ` |
59+ | isCancel | 点击蒙层是否关闭 | Boolean | ` true ` |
6060| dividerStyle | 分割线样式 | DividerStyleProps | - |
6161| containerStyle | 取消的容器样式 | StyleProp<` ViewStyle ` > | - |
6262| activeOpacity | 动作在被触摸操作激活时以多少不透明度显示 | number | ` #f1f1f1 ` |
6363| underlayColor | 动作有触摸操作时显示出来的底层的颜色 | string | ` #f1f1f1 ` |
6464| cancelText | 取消的文本 | ` React.ReactNode ` | - |
6565| textStyle | 取消的文本样式 | ` StyleProp<TextStyle> ` | - |
66+ | onCancel | 蒙层关闭回调 | ` () => void ` | - |
6667
6768### DividerStyleProps
6869| 参数 | 说明 | 类型 | 默认值 |
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export interface DividerStyle {
1313
1414export interface ActionSheetProps extends ModalProps {
1515 /** 点击蒙层是否关闭 */
16- onCancel ?: Boolean ;
16+ isCancel ?: Boolean ;
1717 /** 分割线样式 */
1818 dividerStyle ?: DividerStyle ;
1919 /** 取消的容器样式 */
@@ -26,6 +26,8 @@ export interface ActionSheetProps extends ModalProps {
2626 underlayColor ?: string ;
2727 /** 取消的文本 */
2828 cancelText ?: React . ReactNode ;
29+ /** 蒙层关闭回调 */
30+ onCancel ?: ( ) => void ;
2931}
3032
3133interface ActionSheetState {
@@ -41,9 +43,10 @@ export default function ActionSheet(props: ActionSheetProps) {
4143 underlayColor,
4244 cancelText = '取消' ,
4345 dividerStyle,
44- onCancel ,
46+ isCancel = true ,
4547 containerStyle,
4648 textStyle,
49+ onCancel,
4750 ...other
4851 } = props ;
4952
@@ -70,7 +73,14 @@ export default function ActionSheet(props: ActionSheetProps) {
7073 stateVisible : ! ! props . visible ,
7174 } ) ;
7275 }
73- } , [ state . stateVisible ] ) ;
76+ } , [ state . stateVisible , props . visible ] ) ;
77+
78+ const onModalClose = ( ) => {
79+ if ( isCancel ) {
80+ setState ( { stateVisible : false , control : 'state' } ) ;
81+ onCancel ?.( ) ;
82+ }
83+ } ;
7484
7585 const onClose = ( ) => {
7686 setState ( { stateVisible : false , control : 'state' } ) ;
@@ -83,7 +93,7 @@ export default function ActionSheet(props: ActionSheetProps) {
8393 transparent = { true }
8494 { ...other }
8595 visible = { state . stateVisible }
86- onClosed = { onClose }
96+ onClosed = { onModalClose }
8797 >
8898 < >
8999 { React . Children . toArray ( children ) . map ( ( item , index ) => (
You can’t perform that action at this time.
0 commit comments