Skip to content

Commit dfea5a5

Browse files
committed
feat(Swiper):增加loading api
1 parent 80d1497 commit dfea5a5

File tree

4 files changed

+71
-104
lines changed

4 files changed

+71
-104
lines changed

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

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,92 +13,49 @@ export default class TreeSelectDemo extends React.Component<TreeSelectViewProps>
1313
const title = route.params.title;
1414
const option = [
1515
{
16-
label: '北京',
16+
label: '2月23日(今天)',
1717
value: '01',
1818
children: [
1919
{
20-
label: '东城区',
20+
label: '9:00-10:00',
2121
value: '01-1',
22+
children: [{label: '00:00', value: '01-1-1'}],
2223
},
2324
{
24-
label: '西城区',
25+
label: '10:00-11:00',
2526
value: '01-2',
2627
},
2728
{
28-
label: '崇文区',
29+
label: '11:00-12:00',
2930
value: '01-3',
3031
},
31-
{
32-
label: '宣武区',
33-
value: '01-4',
34-
},
3532
],
3633
},
3734
{
38-
label: '浙江',
35+
label: '2月24日(明天)',
3936
value: '02',
4037
children: [
4138
{
42-
label: '杭州',
39+
label: '9:00-10:00',
4340
value: '02-1',
44-
children: [
45-
{
46-
label: '西湖区',
47-
value: '02-1-1',
48-
},
49-
{
50-
label: '上城区',
51-
value: '02-1-2',
52-
},
53-
{
54-
label: '江干区',
55-
value: '02-1-3',
56-
},
57-
{
58-
label: '下城区',
59-
value: '02-1-4',
60-
},
61-
],
6241
},
6342
{
64-
label: '宁波',
43+
label: '10:00-11:00',
6544
value: '02-2',
66-
children: [
67-
{
68-
label: 'xx区',
69-
value: '02-2-1',
70-
},
71-
{
72-
label: 'yy区',
73-
value: '02-2-2',
74-
},
75-
],
7645
},
7746
{
78-
label: '温州',
47+
label: '11:00-12:00',
7948
value: '02-3',
8049
},
81-
{
82-
label: '嘉兴',
83-
value: '02-4',
84-
},
85-
{
86-
label: '湖州',
87-
value: '02-5',
88-
},
89-
{
90-
label: '绍兴',
91-
value: '02-6',
92-
},
9350
],
9451
},
9552
];
9653
return (
9754
<React.Fragment>
9855
<DragDrawer drawerHeight={500}>
9956
<TreeSelect
100-
defaultValue={['01', '01-1']}
101-
activeColor="#fd8a00"
57+
defaultValue={['01', '01-1', '01-1-1']}
58+
activeColor="red"
10259
options={option}
10360
onChange={(value: any, nodes: any) => {
10461
console.log(value, nodes);

packages/core/src/Swiper/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ export default SwiperDemo
3737
| time | 执行时间 | Number | 3000(3s) |
3838
| borderRadius | 圆角边框 | Number | 0 |
3939
| autoplay | 是否开启定时器 | Boolean | true|
40-
| dotStyle | 圆点类型 ( dot : 圆点, block : 方块 ) | String | dot |
40+
| dotStyle | 圆点类型 ( dot : 圆点, block : 方块 ) | String | dot |
41+
| loading | 加载状态 | Boolean | false |

packages/core/src/Swiper/index.tsx

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
NativeSyntheticEvent,
1010
NativeScrollEvent,
1111
} from 'react-native';
12+
import Loader from '../Loader';
1213
import { colors } from '../utils';
1314
export interface dataSourceType {
1415
url: string;
@@ -30,17 +31,19 @@ export interface SwiperProps {
3031
autoplay?: boolean;
3132
// 指示点样式 dot: 圆点 block: 方块
3233
dotStyle?: dotType;
34+
loading?: boolean;
3335
}
3436
const Swiper = (porps: SwiperProps) => {
3537
const gitwidth = Dimensions.get('window').width;
3638
const {
3739
dataSource = [],
3840
width = gitwidth,
3941
height = 130,
40-
time = 3000,
42+
time = 6000,
4143
autoplay = true,
4244
borderRadius = 0,
4345
dotStyle = 'dot',
46+
loading = false,
4447
} = porps;
4548
let [curIndex, setCurIndex] = useState(0);
4649
let timer = useRef<NodeJS.Timeout | undefined>();
@@ -63,7 +66,7 @@ const Swiper = (porps: SwiperProps) => {
6366

6467
// 开启播放
6568
useEffect(() => {
66-
if (autoplay) autoPlay();
69+
if (autoplay && !loading) autoPlay();
6770
}, [autoPlay]);
6871

6972
// 页面离开停止播放
@@ -97,53 +100,55 @@ const Swiper = (porps: SwiperProps) => {
97100
scrollToRef.current.scrollTo({ x: width * index, y: 0, animated: true });
98101
};
99102
return (
100-
<View style={StyleSheet.flatten([styles.banner, { width, height }])}>
101-
<ScrollView
102-
ref={scrollToRef}
103-
horizontal={true}
104-
showsHorizontalScrollIndicator={false}
105-
pagingEnabled={true}
106-
onScrollBeginDrag={onScrollBeginDrag}
107-
onScrollEndDrag={onScrollEndDrag}
108-
onMomentumScrollEnd={onMomentumScrollEnd}
109-
>
110-
{dataSource.map((item: dataSourceType, index: number) => {
111-
return (
112-
<View key={index} style={{ width, height }}>
113-
<View style={{ padding: 12 }}>
114-
<TouchableOpacity
115-
activeOpacity={1}
116-
onPress={() => {
117-
item.onClick && item.onClick();
118-
}}
119-
>
120-
<Image
121-
key={index}
122-
style={StyleSheet.flatten([{ borderRadius, width: '100%', height: '100%' }])}
123-
resizeMode="cover"
124-
source={typeof item.url === 'number' ? item.url : { uri: item.url }}
125-
/>
126-
</TouchableOpacity>
103+
<Loader loading={loading} rounded={5} maskColor="transparent">
104+
<View style={StyleSheet.flatten([styles.banner, { width, height }])}>
105+
<ScrollView
106+
ref={scrollToRef}
107+
horizontal={true}
108+
showsHorizontalScrollIndicator={false}
109+
pagingEnabled={true}
110+
onScrollBeginDrag={onScrollBeginDrag}
111+
onScrollEndDrag={onScrollEndDrag}
112+
onMomentumScrollEnd={onMomentumScrollEnd}
113+
>
114+
{dataSource.map((item: dataSourceType, index: number) => {
115+
return (
116+
<View key={index} style={{ width, height }}>
117+
<View style={{ padding: 12 }}>
118+
<TouchableOpacity
119+
activeOpacity={1}
120+
onPress={() => {
121+
item.onClick && item.onClick();
122+
}}
123+
>
124+
<Image
125+
key={index}
126+
style={StyleSheet.flatten([{ borderRadius, width: '100%', height: '100%' }])}
127+
resizeMode="cover"
128+
source={typeof item.url === 'number' ? item.url : { uri: item.url }}
129+
/>
130+
</TouchableOpacity>
131+
</View>
127132
</View>
128-
</View>
129-
);
130-
})}
131-
</ScrollView>
132-
<View style={styles.dotBox}>
133-
{dataSource.map((_: dataSourceType, index: number) => {
134-
return (
135-
<TouchableOpacity
136-
onPress={onClickDot.bind(this, index)}
137-
key={index}
138-
style={StyleSheet.flatten([
139-
dotStyle === 'block' ? styles.block : styles.dot,
140-
index === curIndex ? styles.dotSetColor : styles.dotColor,
141-
])}
142-
/>
143-
);
144-
})}
133+
);
134+
})}
135+
</ScrollView>
136+
<View style={styles.dotBox}>
137+
{dataSource.map((_: dataSourceType, index: number) => {
138+
return (
139+
<TouchableOpacity
140+
onPress={onClickDot.bind(this, index)}
141+
key={index}
142+
style={StyleSheet.flatten([
143+
dotStyle === 'block' ? styles.block : styles.dot,
144+
index === curIndex ? styles.dotSetColor : styles.dotColor,
145+
])}
146+
/>
147+
);
148+
})}
149+
</View>
145150
</View>
146-
</View>
151+
</Loader>
147152
);
148153
};
149154
const styles = StyleSheet.create({

packages/core/src/TreeSelect/tree-select.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
7171
};
7272

7373
// item样式
74-
const activeStyles = (index: number, isActive: boolean) => {
74+
const activeStyles = (index: number, isActive: boolean, isLast: boolean) => {
7575
let styles;
7676
// 选中第一排
7777
if (isActive && index === 0) {
@@ -90,12 +90,14 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
9090
styles = {
9191
...style.active_nth_item,
9292
borderColor: props.activeColor,
93+
marginRight: isLast ? 10 : 0,
9394
};
9495
}
9596
// 未选中后排
9697
if (!isActive && index !== 0) {
9798
styles = {
9899
...style.not_active_nth_item,
100+
marginRight: isLast ? 10 : 0,
99101
};
100102
}
101103
return styles;
@@ -105,6 +107,8 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
105107
return columnOptions.map((item) => {
106108
const isActive = item[valueName] === value[index];
107109
const active_font_color = index === 0 ? '#333' : props.activeColor;
110+
// 是否是最后一列
111+
const isLast = deep - 1 === index;
108112
return (
109113
<TouchableOpacity
110114
key={item[valueName]}
@@ -113,7 +117,7 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
113117
onItemSelect(item);
114118
}
115119
}}
116-
style={[style.item, { ...activeStyles(index, isActive) }]}
120+
style={[style.item, { ...activeStyles(index, isActive, isLast) }]}
117121
>
118122
<Text style={isActive ? { color: active_font_color, fontWeight: 'bold' } : { color: '#666' }}>
119123
{item[labelName]}

0 commit comments

Comments
 (0)