Skip to content

Commit 0e7c803

Browse files
committed
feat(ActionBar):新增ActionBar
1 parent 8cdc77c commit 0e7c803

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

example/examples/src/routes.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,12 @@ export const stackPageData: Routes[] = [
490490
description: '可输入多行文字',
491491
},
492492
},
493+
{
494+
name: 'ActionBar',
495+
component: require('./routes/ActionBar').default,
496+
params: {
497+
title: 'ActionBar 底部操作栏',
498+
description: '底部操作栏',
499+
},
500+
},
493501
];
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import {ActionBar} from '@uiw/react-native';
3+
import {View, Alert} from 'react-native';
4+
import {ComProps} from '../../routes';
5+
import Layout from '../../Layout';
6+
const {Header} = Layout;
7+
8+
export interface ActionBarProps extends ComProps {}
9+
10+
export default class ActionBarDemo extends React.Component<ActionBarProps> {
11+
render() {
12+
const {route} = this.props;
13+
const description = route.params.description;
14+
const title = route.params.title;
15+
return (
16+
<React.Fragment>
17+
<Header title={title} description={description} />
18+
<View style={{flex: 1}}>
19+
<ActionBar
20+
backgroundColor="#5847FF"
21+
scroll={false}
22+
actions={[
23+
{
24+
label: 'Delete',
25+
onPress: () => Alert.alert('delete'),
26+
fontStyle: {fontWeight: 'bold', color: '#fff'},
27+
},
28+
{
29+
label: 'Replace',
30+
onPress: () => Alert.alert('replace photo'),
31+
fontStyle: {fontWeight: 'bold', color: '#fff'},
32+
},
33+
{
34+
label: 'Edit',
35+
onPress: () => Alert.alert('edit'),
36+
fontStyle: {fontWeight: 'bold', color: '#fff'},
37+
},
38+
]}
39+
/>
40+
</View>
41+
</React.Fragment>
42+
);
43+
}
44+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ActionBar 底部操作栏
2+
---
3+
4+
底部操作栏
5+
6+
7+
8+
### 基础示例
9+
10+
```jsx
11+
import React from 'react';
12+
import { ActionBar } from '@uiw/react-native';
13+
import { View, Alert } from 'react-native'
14+
15+
export interface ScreenRootProps extends ComProps { }
16+
17+
export default class Demo extends React.Component<ScreenRootProps> {
18+
render() {
19+
return (
20+
<View style={{ flex: 1 }}>
21+
<ActionBar
22+
scroll={false}
23+
actions={[
24+
{ label: 'Delete', onPress: () => Alert.alert('delete'), fontStyle: { fontWeight: 'bold', color: "#5847FF" } },
25+
{ label: 'Replace', onPress: () => Alert.alert('replace photo'), fontStyle: { fontWeight: 'bold', color: "#5847FF" } },
26+
{ label: 'Edit', onPress: () => Alert.alert('edit'), fontStyle: { fontWeight: 'bold', color: "#5847FF" } }
27+
]}
28+
/>
29+
</View>
30+
);
31+
}
32+
}
33+
```
34+
35+
### Props
36+
```tsx
37+
export type ActionBarProps = {
38+
// 高度
39+
height?: number;
40+
// 背景色
41+
backgroundColor?: string;
42+
// 按钮
43+
actions: Array<{
44+
label?: string;
45+
onPress?: () => void;
46+
fontStyle?: TextStyle;
47+
render?: ReactNode
48+
}>;
49+
// 是否在底部
50+
keepAbsoulte?: boolean;
51+
// 在 iOS 中,使用安全区域,以防组件附加到底部
52+
useSafeArea?: boolean;
53+
style?: ViewStyle;
54+
// 是否横向滚动
55+
scroll?: boolean
56+
};
57+
```
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import _ from 'lodash';
2+
import React, { ReactNode, useMemo } from 'react';
3+
import {
4+
StyleSheet,
5+
ViewStyle,
6+
View,
7+
ScrollView,
8+
TouchableOpacity,
9+
Text,
10+
TextStyle,
11+
SafeAreaView,
12+
Platform,
13+
} from 'react-native';
14+
15+
export type ActionBarProps = {
16+
height?: number;
17+
backgroundColor?: string;
18+
actions: Array<{
19+
label?: string;
20+
onPress?: () => void;
21+
fontStyle?: TextStyle;
22+
render?: ReactNode;
23+
}>;
24+
keepAbsoulte?: boolean;
25+
style?: ViewStyle;
26+
scroll?: boolean;
27+
useSafeArea?: boolean;
28+
};
29+
30+
const Container = (props: { scroll: boolean; children: ReactNode; useSafeArea: boolean; style: any }) => {
31+
const { scroll, children, useSafeArea, ...others } = props;
32+
const renderDom = useMemo(() => {
33+
if (scroll) {
34+
return (
35+
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false} {...others}>
36+
{children}
37+
</ScrollView>
38+
);
39+
}
40+
if (!scroll && useSafeArea && Platform.OS === 'ios') {
41+
return <SafeAreaView {...others}>{children}</SafeAreaView>;
42+
}
43+
return <View {...others}>{children}</View>;
44+
}, [scroll, useSafeArea, children]);
45+
return renderDom;
46+
};
47+
48+
function ActionBar(props: ActionBarProps) {
49+
const {
50+
actions,
51+
style,
52+
keepAbsoulte = true,
53+
height = 48,
54+
backgroundColor = '#fff',
55+
scroll = true,
56+
useSafeArea = true,
57+
} = props;
58+
59+
const styles = createStyles({ height: height, backgroundColor: backgroundColor });
60+
61+
// 按钮长度
62+
const actionLeg = actions.length || 0;
63+
64+
// 是否是数组最后一个
65+
const last = (i: number) => actionLeg - 1 === i;
66+
67+
return (
68+
<Container scroll={scroll} useSafeArea={useSafeArea} style={[keepAbsoulte && styles.absoluteContainer]}>
69+
<View style={[styles.container, { justifyContent: 'space-between', ...style }]}>
70+
{_.map(actions, ({ label = '', onPress, render, fontStyle }, i) => {
71+
return (
72+
<TouchableOpacity key={i} onPress={onPress && onPress} style={{ marginRight: scroll && !last(i) ? 20 : 0 }}>
73+
{render ? render : <Text style={{ ...fontStyle }}>{label}</Text>}
74+
</TouchableOpacity>
75+
);
76+
})}
77+
</View>
78+
</Container>
79+
);
80+
}
81+
82+
function createStyles({ height, backgroundColor }: any) {
83+
return StyleSheet.create({
84+
container: {
85+
height,
86+
paddingHorizontal: 20,
87+
flexDirection: 'row',
88+
alignItems: 'center',
89+
},
90+
absoluteContainer: {
91+
...StyleSheet.absoluteFillObject,
92+
top: undefined,
93+
backgroundColor,
94+
shadowColor: '#43515C',
95+
shadowOpacity: 0.06,
96+
shadowRadius: 18.5,
97+
},
98+
});
99+
}
100+
101+
export default ActionBar;

packages/core/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ export { default as TreeSelect } from './TreeSelect';
116116
export * from './TreeSelect';
117117
export { default as TextArea } from './TextArea';
118118
export * from './TextArea';
119+
export { default as ActionBar } from './ActionBar';
120+
export * from './ActionBar';
119121
/**
120122
* Typography
121123
*/

0 commit comments

Comments
 (0)