Skip to content

Commit 66cc807

Browse files
authored
Merge pull request #569 from panbibi/dev
fix(CheckBox&Radio&SegmentedControl):调整CheckBox & Radio & SegmentedCo…
2 parents 3bafa69 + f71c056 commit 66cc807

File tree

4 files changed

+74
-49
lines changed

4 files changed

+74
-49
lines changed

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

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import {Spacing, Radio} from '@uiw/react-native';
33
import {ComProps} from '../../routes';
44
import Layout, {Container} from '../../Layout';
5+
import {View} from 'react-native';
56

67
const {Header, Body, Card, Footer} = Layout;
78

@@ -11,10 +12,7 @@ export interface RadioViewState {
1112
value: number | null;
1213
}
1314

14-
export default class RadioView extends React.Component<
15-
RadioViewProps,
16-
RadioViewState
17-
> {
15+
export default class RadioView extends React.Component<RadioViewProps, RadioViewState> {
1816
constructor(props: RadioViewProps) {
1917
super(props);
2018
this.state = {
@@ -39,41 +37,49 @@ export default class RadioView extends React.Component<
3937
<Header title={title} description={description} />
4038
<Body>
4139
<Card title="基础实例">
42-
<Radio checkedColor="#fd8a00" borderColor="#fd8a00">
43-
所有人可见
44-
</Radio>
45-
<Spacing />
46-
<Radio>超级管理员</Radio>
40+
<View style={{marginLeft: 15}}>
41+
<Radio checkedColor="#fd8a00" borderColor="#fd8a00">
42+
所有人可见
43+
</Radio>
44+
<Spacing />
45+
<Radio>超级管理员</Radio>
46+
</View>
4747
</Card>
4848
<Card title={`受控组件 checked: ${this.state.checked}`}>
49-
<Radio
50-
checked={this.state.checked}
51-
onPress={() => {
52-
this.setState({checked: !this.state.checked});
53-
}}>
54-
所有人可见
55-
</Radio>
49+
<View style={{marginLeft: 15}}>
50+
<Radio
51+
checked={this.state.checked}
52+
onPress={() => {
53+
this.setState({checked: !this.state.checked});
54+
}}>
55+
所有人可见
56+
</Radio>
57+
</View>
5658
</Card>
5759
<Card title={`单选 value: ${this.state.value}`}>
58-
{radioData.map((item, idx) => {
59-
return (
60-
<Radio
61-
key={idx}
62-
checked={this.state.value === item.value}
63-
onPress={() => {
64-
this.setState({value: item.value});
65-
}}>
66-
{item.label}
67-
</Radio>
68-
);
69-
})}
60+
<View style={{marginLeft: 15}}>
61+
{radioData.map((item, idx) => {
62+
return (
63+
<Radio
64+
key={idx}
65+
checked={this.state.value === item.value}
66+
onPress={() => {
67+
this.setState({value: item.value});
68+
}}>
69+
{item.label}
70+
</Radio>
71+
);
72+
})}
73+
</View>
7074
</Card>
7175
<Card title="禁用 checked?: boolean;">
72-
<Radio disabled>所有人可见</Radio>
73-
<Spacing />
74-
<Radio disabled checked={true}>
75-
超级管理员
76-
</Radio>
76+
<View style={{marginLeft: 15}}>
77+
<Radio disabled>所有人可见</Radio>
78+
<Spacing />
79+
<Radio disabled checked={true}>
80+
超级管理员
81+
</Radio>
82+
</View>
7783
</Card>
7884
</Body>
7985
<Footer />

packages/core/src/CheckBox/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
import Icon, { IconsName } from '../Icon';
1313
import { color } from '../utils';
1414
import Div from '../Typography/Div';
15+
import { Theme } from '../theme';
16+
import { useTheme } from '@shopify/restyle';
1517

1618
export interface CheckBoxProps extends TouchableOpacityProps {
1719
textStyle?: StyleProp<TextStyle & ViewStyle>;
@@ -30,6 +32,7 @@ export interface CheckBoxState {
3032
}
3133

3234
function CheckBox(props: CheckBoxProps) {
35+
const theme = useTheme<Theme>();
3336
const [state, setState] = useState({
3437
checked: !!props.checked,
3538
controlChecked: 'props',
@@ -53,13 +56,13 @@ function CheckBox(props: CheckBoxProps) {
5356
children,
5457
style,
5558
textStyle,
56-
checkedIcon,
57-
unCheckedIcon,
59+
checkedIcon = 'circle-check',
60+
unCheckedIcon = 'circle-o',
5861
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5962
checked,
6063
disabled,
61-
color: $color,
62-
size,
64+
color: $color = theme.colors.primary_background || '#3578e5',
65+
size = 16,
6366
...otherProps
6467
} = props;
6568
const { checked: $checked } = state;
@@ -84,12 +87,13 @@ function CheckBox(props: CheckBoxProps) {
8487
);
8588
}
8689

87-
CheckBox.defaultProps = {
88-
checkedIcon: 'circle-check',
89-
unCheckedIcon: 'circle-o',
90-
color: '#008EF0',
91-
size: 16,
92-
};
90+
// console.log('theme', theme);
91+
// CheckBox.defaultProps = {
92+
// checkedIcon: 'circle-check',
93+
// unCheckedIcon: 'circle-o',
94+
// color: '#3578e5', //theme.colors.primary_background,
95+
// size: 16,
96+
// };
9397

9498
export default CheckBox;
9599

packages/core/src/Radio/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
GestureResponderEvent,
1010
StyleSheet,
1111
} from 'react-native';
12+
import { Theme } from '../theme';
13+
import { useTheme } from '@shopify/restyle';
1214

1315
interface MaybeTextOrViewProps {
1416
children?: React.ReactNode;
@@ -61,6 +63,7 @@ export interface RadioState {
6163
}
6264

6365
export default function Radio(props: RadioProps) {
66+
const theme = useTheme<Theme>();
6467
const [state, setState] = useState({
6568
checked: props.checked,
6669
sizeValue: new Animated.Value(0),
@@ -101,7 +104,16 @@ export default function Radio(props: RadioProps) {
101104
onPress && onPress(event);
102105
};
103106

104-
const { style, color, circleSize, thumbSize, disabled, checkedColor, borderColor: bdColor, ...otherProps } = props;
107+
const {
108+
style,
109+
color,
110+
circleSize,
111+
thumbSize,
112+
disabled,
113+
checkedColor = theme.colors.primary_background || '#3578e5',
114+
borderColor: bdColor,
115+
...otherProps
116+
} = props;
105117
const sizeValue = state.sizeValue.interpolate({
106118
inputRange: [0, thumbSize!],
107119
outputRange: [0, thumbSize!],
@@ -138,7 +150,6 @@ export default function Radio(props: RadioProps) {
138150
Radio.defaultProps = {
139151
checked: false,
140152
circleSize: 20,
141-
checkedColor: '#008EF0',
142153
borderColor: '#bdc1cc',
143154
color: '#c3c5c7',
144155
thumbSize: 12,

packages/core/src/SegmentedControl/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState } from 'react';
22
import { ViewStyle, TextStyle, Text } from 'react-native';
33
import ButtonGroup, { ButtonGroupProps } from '../ButtonGroup';
44
import Button from '../Button';
5+
import { Theme } from '../theme';
6+
import { useTheme } from '@shopify/restyle';
57

68
export interface TextColorType {
79
actived?: string;
@@ -13,13 +15,15 @@ export interface SegmentedControlProps<T> extends ButtonGroupProps {
1315
renderItem?: (label: string | T, selectedIndex: number, props: ButtonGroupProps) => JSX.Element;
1416
onValueChange?: (label: string | T, selectedIndex: number) => void;
1517
textColor?: TextColorType;
18+
colors?: string;
1619
}
1720

1821
export interface SegmentedControlState {
1922
selectedIndex: number;
2023
}
2124

2225
export default function SegmentedControl<T extends React.ReactPortal>(props: SegmentedControlProps<T>) {
26+
const theme = useTheme<Theme>();
2327
const [state, setState] = useState({
2428
selectedIndex: props.selectedIndex || 0,
2529
});
@@ -37,9 +41,10 @@ export default function SegmentedControl<T extends React.ReactPortal>(props: Seg
3741
selectedIndex,
3842
renderItem,
3943
textColor = {
40-
actived: '#fff',
41-
unactived: props.color ?? '#108ee9',
44+
actived: theme.colors.text_active || '#fff',
45+
unactived: props.color ?? (theme.colors.primary_background || '#3578e5'),
4246
},
47+
colors = props.color || theme.colors.primary_background || '#3578e5',
4348
...otherProps
4449
} = props;
4550

@@ -52,7 +57,7 @@ export default function SegmentedControl<T extends React.ReactPortal>(props: Seg
5257
let textStyleColor: string = textColor.actived!;
5358
if (state.selectedIndex !== key + 1) {
5459
styl.backgroundColor = '#fff';
55-
textStyle.color = otherProps.color;
60+
textStyle.color = colors;
5661
textStyleColor = textColor.unactived!;
5762
}
5863
const props: ButtonGroupProps = {
@@ -78,5 +83,4 @@ SegmentedControl.defaultProps = {
7883
value: [],
7984
size: 'small',
8085
selectedIndex: 0,
81-
color: '#108ee9',
8286
} as SegmentedControlProps<{}>;

0 commit comments

Comments
 (0)