|
1 | 1 | 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'; |
3 | 3 | import Modal, { ModalProps } from '../Modal';
|
4 | 4 | import ActionSheetItem from './item';
|
5 | 5 | export { default as ActionSheetItem } from './item';
|
| 6 | +import { Theme } from '../theme'; |
| 7 | +import { useTheme } from '@shopify/restyle'; |
6 | 8 |
|
7 | 9 | let MainWidth = Dimensions.get('window').width;
|
8 | 10 |
|
@@ -36,6 +38,14 @@ interface ActionSheetState {
|
36 | 38 | }
|
37 | 39 |
|
38 | 40 | 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 | + |
39 | 49 | const {
|
40 | 50 | children,
|
41 | 51 | visible: props_visible,
|
@@ -118,46 +128,54 @@ export default function ActionSheet(props: ActionSheetProps) {
|
118 | 128 | );
|
119 | 129 | }
|
120 | 130 |
|
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 | +} |
0 commit comments