Skip to content

Commit a1dbe37

Browse files
committed
fix(ActionSheet):添加动作面板明暗主题适配
1 parent dcda7fb commit a1dbe37

File tree

3 files changed

+70
-47
lines changed

3 files changed

+70
-47
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class Index extends Component<IndexProps, IndexState> {
6262

6363
const styles = StyleSheet.create({
6464
card: {
65-
backgroundColor: '#fff',
65+
// backgroundColor: '#fff',
6666
paddingLeft: 20,
6767
paddingRight: 20,
6868
},

packages/core/src/ActionSheet/index.tsx

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { useEffect, useState } from 'react';
2-
import { View, Dimensions, StyleSheet, TextStyle, StyleProp, ViewStyle } from 'react-native';
2+
import { View, Dimensions, StyleSheet, TextStyle, StyleProp, ViewStyle, useColorScheme } from 'react-native';
33
import Modal, { ModalProps } from '../Modal';
44
import ActionSheetItem from './item';
55
export { default as ActionSheetItem } from './item';
6+
import { Theme } from '../theme';
7+
import { useTheme } from '@shopify/restyle';
68

79
let MainWidth = Dimensions.get('window').width;
810

@@ -36,6 +38,14 @@ interface ActionSheetState {
3638
}
3739

3840
export default function ActionSheet(props: ActionSheetProps) {
41+
const theme = useTheme<Theme>();
42+
const colorScheme = useColorScheme();
43+
const styles = createStyles({
44+
backgroundColor: colorScheme === 'dark' ? 'rgba(00,00,00,.3)' : 'rgba(95,95,95,.3)',
45+
primaryBackground: colorScheme === 'dark' ? theme.colors.black : 'rgba(00,00,00,.6)',
46+
mask: theme.colors.mask,
47+
});
48+
3949
const {
4050
children,
4151
visible: props_visible,
@@ -118,46 +128,54 @@ export default function ActionSheet(props: ActionSheetProps) {
118128
);
119129
}
120130

121-
const styles = StyleSheet.create({
122-
actionDivider: {
123-
backgroundColor: 'rgba(95,95,95,.3)',
124-
width: MainWidth,
125-
height: 10,
126-
},
127-
itemDivider: {
128-
backgroundColor: 'rgba(95,95,95,.3)',
129-
height: 1,
130-
width: MainWidth,
131-
marginRight: 15,
132-
},
133-
actionSheetModalView: {
134-
flex: 1,
135-
backgroundColor: 'rgba(00,00,00,.6)',
136-
},
137-
// 取消
138-
actionSheetModalViewClose: {
139-
backgroundColor: '#fff',
140-
marginTop: 8,
141-
marginLeft: 8,
142-
marginRight: 8,
143-
marginBottom: 16,
144-
borderTopRightRadius: 12,
145-
borderTopLeftRadius: 12,
146-
borderBottomRightRadius: 12,
147-
borderBottomLeftRadius: 12,
148-
outline: 'none',
149-
boxShadow: 'none',
150-
},
151-
// 内容
152-
actionSheetModalViewContent: {
153-
marginLeft: 8,
154-
marginRight: 8,
155-
backgroundColor: '#fff',
156-
borderTopRightRadius: 12,
157-
borderTopLeftRadius: 12,
158-
borderBottomRightRadius: 12,
159-
borderBottomLeftRadius: 12,
160-
outline: 'none',
161-
boxShadow: 'none',
162-
},
163-
});
131+
type CreStyle = {
132+
backgroundColor: string;
133+
primaryBackground: string;
134+
mask: string;
135+
};
136+
137+
function createStyles({ backgroundColor, primaryBackground, mask }: CreStyle) {
138+
return StyleSheet.create({
139+
actionDivider: {
140+
backgroundColor: backgroundColor,
141+
width: MainWidth,
142+
height: 10,
143+
},
144+
itemDivider: {
145+
backgroundColor: backgroundColor,
146+
height: 1,
147+
width: MainWidth,
148+
marginRight: 15,
149+
},
150+
actionSheetModalView: {
151+
flex: 1,
152+
backgroundColor: primaryBackground,
153+
},
154+
// 取消
155+
actionSheetModalViewClose: {
156+
backgroundColor: mask,
157+
marginTop: 8,
158+
marginLeft: 8,
159+
marginRight: 8,
160+
marginBottom: 16,
161+
borderTopRightRadius: 12,
162+
borderTopLeftRadius: 12,
163+
borderBottomRightRadius: 12,
164+
borderBottomLeftRadius: 12,
165+
outline: 'none',
166+
boxShadow: 'none',
167+
},
168+
// 内容
169+
actionSheetModalViewContent: {
170+
marginLeft: 8,
171+
marginRight: 8,
172+
backgroundColor: mask,
173+
borderTopRightRadius: 12,
174+
borderTopLeftRadius: 12,
175+
borderBottomRightRadius: 12,
176+
borderBottomLeftRadius: 12,
177+
outline: 'none',
178+
boxShadow: 'none',
179+
},
180+
});
181+
}

packages/core/src/ActionSheet/item.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import {
77
ViewStyle,
88
TextStyle,
99
StyleSheet,
10-
Text,
1110
GestureResponderEvent,
11+
useColorScheme,
1212
} from 'react-native';
13+
import { useTheme } from '@shopify/restyle';
14+
import { Theme } from '../theme';
15+
import Text from '../Typography/Text';
1316

1417
let MainWidth = Dimensions.get('window').width;
1518
export interface ActionSheetItemProps {
@@ -28,10 +31,12 @@ export interface ActionSheetItemProps {
2831
export interface ActionSheetItemState {}
2932

3033
export default function ActionSheetItem(props: ActionSheetItemProps) {
34+
const theme = useTheme<Theme>();
35+
const colorScheme = useColorScheme();
3136
const {
3237
onPress = () => {},
3338
activeOpacity = 1,
34-
underlayColor = '#f1f1f1',
39+
underlayColor = colorScheme === 'light' ? theme.colors.background : '#1A1A22',
3540
containerStyle,
3641
textStyle,
3742
children,

0 commit comments

Comments
 (0)