Skip to content

Commit fc0a9d9

Browse files
committed
chore(ActionSheet): Add (textStyle,containerStyle,activeOpacity,underlayColor) of props
1 parent 6d5f8da commit fc0a9d9

File tree

4 files changed

+125
-44
lines changed

4 files changed

+125
-44
lines changed

example/examples/src/routes/ActionSheet/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component} from 'react';
2-
import {StyleSheet, View} from 'react-native';
2+
import {StyleSheet, View, Text} from 'react-native';
33
import Layout, {Container} from '../../Layout';
44
import {ActionSheet, Button, ActionSheetItem, Toast} from '@uiw/react-native';
55
import {ComProps} from '../../routes';
@@ -36,7 +36,12 @@ export default class Index extends Component<IndexProps, IndexState> {
3636
<Body>
3737
<View style={styles.divider} />
3838
<Button onPress={this.onOpen}>打开 ActionSheet</Button>
39-
<ActionSheet visible={this.state.visible} onCancel={true}>
39+
<ActionSheet
40+
visible={this.state.visible}
41+
onCancel={true}
42+
dividerStyle={{
43+
itemDivider: {height: 2},
44+
}}>
4045
<ActionSheetItem
4146
onPress={() => Toast.info('你点击了按钮一', 2, 'info')}>
4247
按钮一

packages/core/src/ActionSheet/README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,42 @@ function Demo() {
5050
## Props
5151

5252
```ts
53-
import { ModalProps } from 'react-native';
53+
import { ModalProps, StyleProp, ViewStyle } from 'react-native';
54+
55+
export interface DividerStyle {
56+
itemDivider?: StyleProp<ViewStyle>,
57+
actionDivider?: StyleProp<ViewStyle>,
58+
}
5459

5560
export interface ActionSheetProps extends ModalProps {
5661
/** 点击蒙层是否关闭 */
57-
onCancel?: Boolean,
58-
/** 是否展示元素 */
59-
visible: Boolean,
62+
onCancel?: Boolean;
63+
/** 分割线样式 */
64+
dividerStyle?: DividerStyle;
65+
/** 取消的容器样式 */
66+
containerStyle?: StyleProp<ViewStyle>;
67+
/** 动作在被触摸操作激活时以多少不透明度显示 默认 1 */
68+
activeOpacity?: number;
69+
/** 动作有触摸操作时显示出来的底层的颜色 默认 #f1f1f1 */
70+
underlayColor?: string;
71+
/** 取消的文本样式 */
72+
textStyle?: StyleProp<TextStyle>;
6073
/** 取消的文本 */
61-
cancelText?: React.ReactNode
74+
cancelText?: React.ReactNode;
6275
}
6376
```
6477

6578
## ActionSheetItem Props
6679

6780
```ts
68-
export interface ActionSheetProps extends ModalProps {
69-
/** 点击 Item 触发的事件 */
81+
import { TextStyle, StyleProp, ViewStyle } from 'react-native';
82+
83+
export interface ActionSheetItemProps {
84+
/** 容器样式 */
85+
containerStyle?: StyleProp<ViewStyle>;
86+
/** 文本样式 */
87+
textStyle?: StyleProp<TextStyle>;
88+
/** 点击 ActionSheetItem 触发的事件 */
7089
onPress?: ((event: GestureResponderEvent) => void),
7190
}
7291
```

packages/core/src/ActionSheet/index.tsx

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
import React from 'react';
2-
import { View, Dimensions, StyleSheet, Text, TouchableOpacity, Modal, ModalProps, Animated } from 'react-native';
2+
import {
3+
View,
4+
Dimensions,
5+
StyleSheet,
6+
TextStyle,
7+
StyleProp,
8+
ViewStyle,
9+
TouchableOpacity,
10+
Modal,
11+
ModalProps,
12+
Animated,
13+
} from 'react-native';
314
export { default as ActionSheetItem } from './item';
15+
import ActionSheetItem from './item';
416

517
let MainWidth = Dimensions.get('window').width;
618
let MainHeight = Dimensions.get('window').height;
19+
20+
export interface DividerStyle {
21+
itemDivider?: StyleProp<ViewStyle>;
22+
actionDivider?: StyleProp<ViewStyle>;
23+
}
24+
725
export interface ActionSheetProps extends ModalProps {
826
/** 点击蒙层是否关闭 */
927
onCancel?: Boolean;
28+
/** 分割线样式 */
29+
dividerStyle?: DividerStyle;
30+
/** 取消的容器样式 */
31+
containerStyle?: StyleProp<ViewStyle>;
32+
/** 取消的文本样式 */
33+
textStyle?: StyleProp<TextStyle>;
34+
/** 动作在被触摸操作激活时以多少不透明度显示 默认 1 */
35+
activeOpacity?: number;
36+
/** 动作有触摸操作时显示出来的底层的颜色 */
37+
underlayColor?: string;
1038
/** 取消的文本 */
1139
cancelText?: React.ReactNode;
1240
}
@@ -23,7 +51,7 @@ export default class ActionSheet extends React.Component<ActionSheetProps, Actio
2351
super(props);
2452
this.state = {
2553
animatedHeight: 0,
26-
stateVisible: false,
54+
stateVisible: !!props.visible,
2755
};
2856
}
2957

@@ -62,7 +90,18 @@ export default class ActionSheet extends React.Component<ActionSheetProps, Actio
6290
}
6391
}
6492
render() {
65-
const { children, visible, cancelText = '取消', onCancel, ...other } = this.props;
93+
const {
94+
children,
95+
visible,
96+
activeOpacity,
97+
underlayColor,
98+
cancelText = '取消',
99+
dividerStyle,
100+
onCancel,
101+
containerStyle,
102+
textStyle,
103+
...other
104+
} = this.props;
66105
const { stateVisible } = this.state;
67106
return (
68107
<Modal
@@ -88,20 +127,22 @@ export default class ActionSheet extends React.Component<ActionSheetProps, Actio
88127
>
89128
{React.Children.toArray(children).map((item, index) => (
90129
<View key={index}>
91-
{index !== 0 && <View style={styles.actionSheetItemDivider} />}
92-
{item}
130+
{index !== 0 && <View style={StyleSheet.flatten([styles.itemDivider, dividerStyle?.itemDivider])} />}
131+
{React.cloneElement(item as React.DetailedReactHTMLElement<any, HTMLElement>, {
132+
activeOpacity: activeOpacity,
133+
underlayColor: underlayColor,
134+
})}
93135
</View>
94136
))}
95-
<View style={styles.divider} />
96-
{typeof cancelText !== 'object' ? (
97-
<TouchableOpacity activeOpacity={1} onPress={this.onClose}>
98-
<View style={styles.actionSheetItem}>
99-
<Text style={styles.actionSheetItemText}>{cancelText}</Text>
100-
</View>
101-
</TouchableOpacity>
102-
) : (
103-
<View>{cancelText}</View>
104-
)}
137+
<View style={StyleSheet.flatten([styles.actionDivider, dividerStyle?.actionDivider])} />
138+
<ActionSheetItem
139+
activeOpacity={activeOpacity}
140+
underlayColor={underlayColor}
141+
onPress={this.onClose}
142+
children={cancelText}
143+
containerStyle={containerStyle}
144+
textStyle={textStyle}
145+
/>
105146
</Animated.View>
106147
</Modal>
107148
);
@@ -134,24 +175,14 @@ const styles = StyleSheet.create({
134175
backgroundColor: '#fff',
135176
zIndex: 9999,
136177
},
137-
divider: {
178+
actionDivider: {
138179
backgroundColor: 'rgba(197,217,232,.3)',
139180
width: MainWidth,
140181
height: 6,
141182
},
142-
actionSheetItemDivider: {
143-
borderBottomColor: 'rgba(197,217,232,.3)',
144-
borderBottomWidth: 2,
145-
width: MainWidth,
146-
},
147-
actionSheetItem: {
183+
itemDivider: {
184+
backgroundColor: 'rgba(197,217,232,.3)',
185+
height: 2,
148186
width: MainWidth,
149-
height: 50,
150-
justifyContent: 'center',
151-
alignItems: 'center',
152-
},
153-
actionSheetItemText: {
154-
fontSize: 20,
155-
fontWeight: '400',
156187
},
157188
});

packages/core/src/ActionSheet/item.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
import React from 'react';
2-
import { View, Dimensions, StyleSheet, Text, TouchableOpacity, GestureResponderEvent } from 'react-native';
2+
import {
3+
View,
4+
Dimensions,
5+
TouchableHighlight,
6+
StyleProp,
7+
ViewStyle,
8+
TextStyle,
9+
StyleSheet,
10+
Text,
11+
TouchableOpacity,
12+
GestureResponderEvent,
13+
} from 'react-native';
314

415
let MainWidth = Dimensions.get('window').width;
516
export interface ActionSheetItemProps {
17+
/** 容器样式 */
18+
containerStyle?: StyleProp<ViewStyle>;
19+
/** 文本样式 */
20+
textStyle?: StyleProp<TextStyle>;
21+
/** 指定封装的视图在被触摸操作激活时以多少不透明度显示 默认 1 */
22+
activeOpacity?: number;
23+
/** 有触摸操作时显示出来的底层的颜色 */
24+
underlayColor?: string;
625
onPress?: (event: GestureResponderEvent) => void;
726
}
827

928
export interface ActionSheetItemState {}
1029

1130
export default class ActionSheetItem extends React.Component<ActionSheetItemProps, ActionSheetItemState> {
1231
render() {
13-
const { onPress = () => {}, children } = this.props;
32+
const {
33+
onPress = () => {},
34+
activeOpacity = 1,
35+
underlayColor = '#f1f1f1',
36+
containerStyle,
37+
textStyle,
38+
children,
39+
} = this.props;
1440
return (
15-
<TouchableOpacity activeOpacity={1} onPress={onPress}>
16-
<View style={styles.actionSheetItem}>
17-
<Text style={styles.actionSheetItemText}>{children}</Text>
41+
<TouchableHighlight activeOpacity={activeOpacity} underlayColor={underlayColor} onPress={onPress}>
42+
<View style={StyleSheet.flatten([styles.actionSheetItem, containerStyle])}>
43+
<Text style={StyleSheet.flatten([styles.actionSheetItemText, textStyle])}>{children}</Text>
1844
</View>
19-
</TouchableOpacity>
45+
</TouchableHighlight>
2046
);
2147
}
2248
}

0 commit comments

Comments
 (0)