Skip to content

Commit ca54fbc

Browse files
committed
fix(SpeedDial&Stepper&Steps):调整SpeedDial & Stepper & Steps主题色配置
1 parent 0a0b6dc commit ca54fbc

File tree

5 files changed

+220
-159
lines changed

5 files changed

+220
-159
lines changed

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

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,78 +36,92 @@ export default class StepperExample extends React.Component<IndexProps, IndexSta
3636
<Header title={title} description={description} />
3737
<Body>
3838
<Card title="基础实例">
39-
<Stepper
40-
value={this.state.value}
41-
onChange={value => {
42-
this.setState({value});
43-
}}
44-
/>
39+
<View style={{marginLeft: 15}}>
40+
<Stepper
41+
value={this.state.value}
42+
onChange={value => {
43+
this.setState({value});
44+
}}
45+
/>
46+
</View>
4547
</Card>
4648

4749
<Card title="尺寸控制(size: small | default | large):">
48-
<Stepper
49-
size="small"
50-
value={this.state.value}
51-
onChange={value => {
52-
this.setState({value});
53-
}}
54-
/>
50+
<View style={{marginLeft: 15}}>
51+
<Stepper
52+
size="small"
53+
value={this.state.value}
54+
onChange={value => {
55+
this.setState({value});
56+
}}
57+
/>
58+
</View>
5559
</Card>
5660

5761
<Card title="按钮开启长按(disabledLongPress: boolean):">
58-
<Stepper
59-
disabledLongPress={true}
60-
value={this.state.value2}
61-
onChange={value2 => {
62-
this.setState({value2});
63-
}}
64-
/>
62+
<View style={{marginLeft: 15}}>
63+
<Stepper
64+
disabledLongPress={true}
65+
value={this.state.value2}
66+
onChange={value2 => {
67+
this.setState({value2});
68+
}}
69+
/>
70+
</View>
6571
</Card>
6672

6773
<Card title="自定义宽度(width: number):">
68-
<Stepper
69-
width={120}
70-
value={this.state.value2}
71-
onChange={value2 => {
72-
this.setState({value2});
73-
}}
74-
/>
74+
<View style={{marginLeft: 15}}>
75+
<Stepper
76+
width={120}
77+
value={this.state.value2}
78+
onChange={value2 => {
79+
this.setState({value2});
80+
}}
81+
/>
82+
</View>
7583
</Card>
7684

7785
<Card title="自定义颜色(color: Color):">
78-
<Stepper
79-
value={this.state.value}
80-
color={{
81-
color: '#ccc',
82-
borderColor: '#999',
83-
controlColor: 'red',
84-
valueColor: '#000',
85-
}}
86-
onChange={value => {
87-
this.setState({value});
88-
}}
89-
/>
86+
<View style={{marginLeft: 15}}>
87+
<Stepper
88+
value={this.state.value}
89+
color={{
90+
color: '#ccc',
91+
borderColor: '#999',
92+
controlColor: 'red',
93+
valueColor: '#000',
94+
}}
95+
onChange={value => {
96+
this.setState({value});
97+
}}
98+
/>
99+
</View>
90100
</Card>
91101

92102
<Card title="不禁止输入(disabledInput: boolean):">
93-
<Stepper
94-
disabledInput={false}
95-
value={this.state.value1}
96-
onChange={value1 => {
97-
this.setState({value1});
98-
}}
99-
/>
103+
<View style={{marginLeft: 15}}>
104+
<Stepper
105+
disabledInput={false}
106+
value={this.state.value1}
107+
onChange={value1 => {
108+
this.setState({value1});
109+
}}
110+
/>
111+
</View>
100112
</Card>
101113

102114
<Card title="禁止点击(disabled: boolean):">
103-
<Stepper
104-
disabled={true}
105-
disabledInput={false}
106-
value={this.state.value1}
107-
onChange={value1 => {
108-
this.setState({value1});
109-
}}
110-
/>
115+
<View style={{marginLeft: 15}}>
116+
<Stepper
117+
disabled={true}
118+
disabledInput={false}
119+
value={this.state.value1}
120+
onChange={value1 => {
121+
this.setState({value1});
122+
}}
123+
/>
124+
</View>
111125
</Card>
112126
</Body>
113127
<Footer />

packages/core/src/SpeedDial/SpeedDialItem.tsx

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useMemo } from 'react';
22
import { View, StyleSheet, Text, TouchableOpacity, ViewStyle, GestureResponderHandlers } from 'react-native';
33
import Icon, { IconsName } from '../Icon';
44
import { TabsItemIconTypes } from '../Tabs/TabsItem';
5+
import { Theme } from '../theme';
6+
import { useTheme } from '@shopify/restyle';
57

68
export interface SpeedDialItemProps {
79
/** 右边 显示的图标 */
@@ -20,6 +22,11 @@ export interface SpeedDialItemProps {
2022
}
2123

2224
function SpeedDialItem(props: SpeedDialItemProps) {
25+
const theme = useTheme<Theme>();
26+
27+
const styles = createStyles({
28+
bgColor: theme.colors.primary_background,
29+
});
2330
const { title, icon, titleStyle, iconStyle, onPress } = props;
2431

2532
const ChildTitle = useMemo(() => {
@@ -52,28 +59,35 @@ function SpeedDialItem(props: SpeedDialItemProps) {
5259
);
5360
}
5461

55-
const styles = StyleSheet.create({
56-
speedDialItemContainer: {
57-
flexDirection: 'row',
58-
alignItems: 'center',
59-
marginBottom: 20,
60-
marginRight: 10,
61-
},
62-
speedDialItemTitle: {
63-
backgroundColor: '#fff',
64-
paddingHorizontal: 10,
65-
height: 30,
66-
borderRadius: 5,
67-
justifyContent: 'center',
68-
marginRight: 20,
69-
},
70-
speedDialItemIcon: {
71-
width: 40,
72-
height: 40,
73-
backgroundColor: '#b779e2',
74-
borderRadius: 20,
75-
justifyContent: 'center',
76-
alignItems: 'center',
77-
},
78-
});
62+
type CreStyle = {
63+
bgColor: string;
64+
};
65+
66+
function createStyles({ bgColor }: CreStyle) {
67+
return StyleSheet.create({
68+
speedDialItemContainer: {
69+
flexDirection: 'row',
70+
alignItems: 'center',
71+
marginBottom: 20,
72+
marginRight: 10,
73+
},
74+
speedDialItemTitle: {
75+
backgroundColor: '#fff',
76+
paddingHorizontal: 10,
77+
height: 30,
78+
borderRadius: 5,
79+
justifyContent: 'center',
80+
marginRight: 20,
81+
},
82+
speedDialItemIcon: {
83+
width: 40,
84+
height: 40,
85+
backgroundColor: bgColor,
86+
borderRadius: 20,
87+
justifyContent: 'center',
88+
alignItems: 'center',
89+
},
90+
});
91+
}
92+
7993
export default SpeedDialItem;

packages/core/src/SpeedDial/index.tsx

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
import Icon, { IconsName } from '../Icon';
1515
import { icoType } from '../Rating';
1616
import Item, { SpeedDialItemProps } from './SpeedDialItem';
17+
import { Theme } from '../theme';
18+
import { useTheme } from '@shopify/restyle';
1719

1820
if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
1921
UIManager.setLayoutAnimationEnabledExperimental(true);
@@ -51,6 +53,11 @@ export interface SpeedDialProps {
5153
}
5254

5355
function SpeedDial(props: SpeedDialProps) {
56+
const theme = useTheme<Theme>();
57+
58+
const styles = createStyles({
59+
bgColor: theme.colors.primary_background,
60+
});
5461
const {
5562
icon = ['plus', 'close'],
5663
style,
@@ -113,14 +120,14 @@ function SpeedDial(props: SpeedDialProps) {
113120
if (icon[0] instanceof Object) {
114121
return <React.Fragment>{icon[0]}</React.Fragment>;
115122
} else {
116-
return <Icon name={icon[0] as IconsName} color="#fff" size={18} />;
123+
return <Icon name={icon[0] as IconsName} color={theme.colors.white} size={18} />;
117124
}
118125
}, []);
119126
const CloseDom = useMemo(() => {
120127
if (icon[1] instanceof Object) {
121128
return <React.Fragment>{icon[1]}</React.Fragment>;
122129
} else {
123-
return <Icon name={icon[1] as IconsName} color="#fff" size={18} />;
130+
return <Icon name={icon[1] as IconsName} color={theme.colors.white} size={18} />;
124131
}
125132
}, []);
126133
const onOpenHome = () => {
@@ -174,24 +181,30 @@ function SpeedDial(props: SpeedDialProps) {
174181
);
175182
}
176183

177-
const styles = StyleSheet.create({
178-
fadingContainer: {
179-
alignItems: 'flex-end',
180-
opacity: 0,
181-
},
182-
viewPosition: {
183-
position: 'absolute',
184-
},
184+
type CreStyle = {
185+
bgColor: string;
186+
};
187+
188+
function createStyles({ bgColor }: CreStyle) {
189+
return StyleSheet.create({
190+
fadingContainer: {
191+
alignItems: 'flex-end',
192+
opacity: 0,
193+
},
194+
viewPosition: {
195+
position: 'absolute',
196+
},
185197

186-
homeContainer: {
187-
width: 60,
188-
height: 60,
189-
backgroundColor: '#b779e2',
190-
borderRadius: 30,
191-
flexDirection: 'row',
192-
justifyContent: 'center',
193-
alignItems: 'center',
194-
},
195-
});
198+
homeContainer: {
199+
width: 60,
200+
height: 60,
201+
backgroundColor: bgColor,
202+
borderRadius: 30,
203+
flexDirection: 'row',
204+
justifyContent: 'center',
205+
alignItems: 'center',
206+
},
207+
});
208+
}
196209

197210
export default SpeedDial;

packages/core/src/Stepper/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { View, TextInput } from 'react-native';
33
import ControlValue from './ControlValue';
44
import ShowValue from './ShowValue';
55
import { styles as ControlStyle } from './ControlValue';
6+
import { Theme } from '../theme';
7+
import { useTheme } from '@shopify/restyle';
68

79
export interface Color {
810
/** 组件主色调 #108ee9 */
@@ -45,13 +47,14 @@ export interface StepProps {
4547
}
4648

4749
function Stepper(props: StepProps) {
50+
const theme = useTheme<Theme>();
4851
const {
4952
size = 'default',
5053
color = {
51-
color: '#108ee9',
52-
borderColor: '#108ee9',
53-
controlColor: '#108ee9',
54-
valueColor: '#108ee9',
54+
color: theme.colors.primary_background,
55+
borderColor: theme.colors.primary_background,
56+
controlColor: theme.colors.primary_background,
57+
valueColor: theme.colors.primary_background,
5558
},
5659
value = 0,
5760
step = 1,

0 commit comments

Comments
 (0)