Skip to content

Commit 2db9e32

Browse files
committed
1. 新增,切换主题的功能
2. 重构Main
1 parent e767df4 commit 2db9e32

File tree

14 files changed

+374
-72
lines changed

14 files changed

+374
-72
lines changed

app/components/NavigatorBar/index.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,22 @@ class NavigatorBar extends React.PureComponent<Props> {
5454
return (
5555
<NavigationBar
5656
leftView={this.renderLeftView()}
57-
background={
58-
!this.props.isNotBackground ? (
59-
<LinearGradient
60-
start={{ x: 0.0, y: 0.25 }}
61-
end={{ x: 0.5, y: 1.0 }}
62-
locations={[0, 1]}
63-
colors={['rgb(13,199,255)', 'rgb(16,174,255)']}
64-
style={{
65-
height: Theme.statusBarHeight + Theme.navBarContentHeight
66-
}}
67-
/>
68-
) : (
69-
this.props.background
70-
)
71-
}
57+
// background={
58+
// !this.props.isNotBackground ? (
59+
// <LinearGradient
60+
// start={{ x: 0.0, y: 0.25 }}
61+
// end={{ x: 0.5, y: 1.0 }}
62+
// locations={[0, 1]}
63+
// // colors={['rgb(13,199,255)', 'rgb(16,174,255)']}
64+
// colors={['rgb(255,255,255)', 'rgb(16,174,255)']}
65+
// style={{
66+
// height: Theme.statusBarHeight + Theme.navBarContentHeight
67+
// }}
68+
// />
69+
// ) : (
70+
// this.props.background
71+
// )
72+
// }
7273
titleStyle={{
7374
fontSize: System.iOS ? 23 : 20,
7475
color: 'white',

app/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Created by Rabbit on 2018/4/12.
44
*/
55

6-
import React, { useEffect } from 'react';
6+
import React, { useContext, useEffect } from 'react';
77
import { View, ActivityIndicator, DeviceEventEmitter, BackHandler, ToastAndroid, StyleSheet } from 'react-native';
88

99
import { AuthLoadingRouter } from './routers/AuthLoading';
@@ -19,7 +19,7 @@ let lastBackPressed: number;
1919
function index() {
2020
useEffect(() => {
2121
SplashScreen.hide();
22-
DeviceEventEmitter.emit('badgeNumber', 30);
22+
// themeStore.setBlackTheme();
2323
return () => {
2424
BackHandler.removeEventListener('hardwareBackPress', this.onBackButtonPressAndroid);
2525
};

app/pages/Main/index.js

Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Created by Rabbit on 2018/4/12.
44
*/
55

6-
import React, { Component } from 'react';
6+
import React, { Component, useContext, useRef, useState } from 'react';
77
import {
88
StyleSheet,
99
Text,
@@ -15,19 +15,138 @@ import {
1515
BackHandler,
1616
DeviceEventEmitter
1717
} from 'react-native';
18-
1918
import { Button, GradientButton, PopoverPickerViewItem } from '../../components';
2019
import Icon from 'react-native-vector-icons/Ionicons';
21-
import { Label, ListRow, PopoverPicker, Badge } from 'teaset';
20+
import { Label, ListRow, PopoverPicker, Badge, Overlay } from 'teaset';
2221
import BaseContainer from '../../components/BaseContainer';
23-
import { createBottomTabNavigator, BottomTabBar } from 'react-navigation-tabs';
22+
import BlackTheme from '../../resource/thems/BlackTheme';
23+
import { StoreContext } from '../../utils/Tool';
24+
import { observer } from 'mobx-react-lite';
2425

2526
type Props = {
2627
navigation: any,
2728
defaultValue: string
2829
};
2930

30-
export class Main extends Component<Props, any> {
31+
let badgeNumber: number = 10;
32+
const items = ['扫一扫', '加好友/群', '首付款', '高能舞室'];
33+
34+
const Main = observer((props: Props) => {
35+
const store = useContext(StoreContext);
36+
const { themeStore } = store;
37+
38+
const popViewRef: PopoverPicker = useRef();
39+
const [modalSelectedIndex, setModalSelectedIndex] = useState(0);
40+
41+
function login(type: string) {
42+
if (type === 'router') {
43+
props.navigation.navigate('AuthRouter', { type });
44+
} else {
45+
props.navigation.navigate('Login', { type });
46+
}
47+
}
48+
49+
function openModalPress(popView: any) {
50+
const blackStyle = {
51+
backgroundColor: '#fff',
52+
paddingLeft: 12,
53+
paddingRight: 12
54+
};
55+
56+
popView.measure((x, y, width, height, pageX, pageY) => {
57+
PopoverPicker.show(
58+
{ x: pageX + 1, y: pageY, width, height },
59+
items,
60+
modalSelectedIndex,
61+
(item, index) => setModalSelectedIndex(index),
62+
{
63+
showArrow: true,
64+
align: 'end',
65+
popoverStyle: blackStyle,
66+
overlayOpacity: 0.3,
67+
directionInsets: -3
68+
}
69+
);
70+
});
71+
}
72+
73+
function renderRightView() {
74+
return (
75+
<Button onPress={() => openModalPress(popViewRef.current)}>
76+
<View ref={popViewRef} style={{ marginRight: px2dp(20) }}>
77+
<Icon name={'md-add'} size={30} color={themeStore.themes.addColor} />
78+
</View>
79+
</Button>
80+
);
81+
}
82+
83+
function addBadgeNumber() {
84+
DeviceEventEmitter.emit('badgeNumber', badgeNumber++);
85+
}
86+
87+
return (
88+
<BaseContainer
89+
style={styles.container}
90+
isTopNavigator={true}
91+
title={'我的'}
92+
rightView={renderRightView()}
93+
onWillBlur={payload => {
94+
console.log('Main页面将要失去焦点', payload);
95+
}}
96+
onDidBlur={payload => {
97+
console.log('Main页面已经失去焦点', payload);
98+
}}
99+
onWillFocus={payload => {
100+
console.log('Main页面将要获得焦点', payload);
101+
}}
102+
onDidFocus={payload => {
103+
console.log('Main页面已经获得焦点', payload);
104+
}}
105+
>
106+
<View style={{ alignItems: 'center' }}>
107+
<GradientButton
108+
title={'切换路由的登录方式'}
109+
onPress={() => login('router')}
110+
gradientStyle={styles.gradientStyle}
111+
titleStyle={styles.btnTitleStyle}
112+
btnStyle={styles.btnStyle}
113+
/>
114+
<GradientButton
115+
title={'直接跳转的登录方式'}
116+
onPress={() => login('navigate')}
117+
gradientStyle={styles.gradientStyle}
118+
titleStyle={styles.btnTitleStyle}
119+
btnStyle={styles.btnStyle}
120+
/>
121+
<GradientButton
122+
title={'添加通知数量'}
123+
onPress={() => addBadgeNumber()}
124+
gradientStyle={styles.gradientStyle}
125+
titleStyle={styles.btnTitleStyle}
126+
btnStyle={styles.btnStyle}
127+
/>
128+
<GradientButton
129+
title={'我的资料'}
130+
onPress={() => props.navigation.navigate('MainData')}
131+
gradientStyle={styles.gradientStyle}
132+
titleStyle={styles.btnTitleStyle}
133+
btnStyle={styles.btnStyle}
134+
/>
135+
<GradientButton
136+
title={'更换主题'}
137+
onPress={() => {
138+
props.navigation.navigate('ThemeScreen');
139+
}}
140+
gradientStyle={styles.gradientStyle}
141+
titleStyle={styles.btnTitleStyle}
142+
btnStyle={styles.btnStyle}
143+
/>
144+
</View>
145+
</BaseContainer>
146+
);
147+
});
148+
149+
class Main1 extends Component<Props, any> {
31150
items: Array<any>;
32151
popView: any;
33152
badgeNumber: number = 10;
@@ -140,6 +259,15 @@ export class Main extends Component<Props, any> {
140259
titleStyle={styles.btnTitleStyle}
141260
btnStyle={styles.btnStyle}
142261
/>
262+
<GradientButton
263+
title={'更换主题'}
264+
onPress={() => {
265+
this.props.navigation.navigate('ThemeScreen');
266+
}}
267+
gradientStyle={styles.gradientStyle}
268+
titleStyle={styles.btnTitleStyle}
269+
btnStyle={styles.btnStyle}
270+
/>
143271
</View>
144272
</BaseContainer>
145273
);
@@ -164,3 +292,5 @@ const styles = StyleSheet.create({
164292
color: 'white'
165293
}
166294
});
295+
296+
export { Main };

app/pages/News/News.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { TabView, TabBar } from 'react-native-tab-view';
2121

2222
type typeItem = {
2323
title: string,
24-
type: string,
25-
key: number
24+
type: string | number,
25+
key: string
2626
};
2727

2828
const typeArr: Array<typeItem> = [
@@ -41,7 +41,8 @@ const typeData = {
4141
const News = observer(props => {
4242
const store = useContext(StoreContext);
4343
const { navigation } = props;
44-
const { publicStore, shiTuStore } = store;
44+
const { publicStore, shiTuStore, themeStore } = store;
45+
const { themes } = themeStore;
4546

4647
const [type, setType] = useState(typeData);
4748

@@ -61,15 +62,14 @@ const News = observer(props => {
6162
indicatorStyle={styles.indicator}
6263
style={styles.tabbar}
6364
tabStyle={styles.tab}
64-
labelStyle={styles.label}
65+
labelStyle={[styles.label, { color: themes.labelColor }]}
6566
activeColor={'#4ECBFC'}
6667
inactiveColor={'black'}
6768
/>
6869
);
6970
}
7071

7172
function _renderScene({ route, jumpTo }: { route: typeItem, jumpTo: Function }) {
72-
// console.log('route', route);
7373
if (route.key === 'WELFARE') {
7474
return (
7575
<Welfare

app/pages/ShiTu/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*/
55

66
import React, { useEffect, useContext } from 'react';
7-
import { StyleSheet, ImageBackground } from 'react-native';
7+
import { StyleSheet, ImageBackground, DeviceEventEmitter } from 'react-native';
88

99
import { GradientButton, PopoverActionSheetItem } from '../../components';
1010
import BaseContainer from '../../components/BaseContainer';
1111
import { System } from '../../utils';
12-
// import { observer, inject } from 'mobx-react';
1312
import { observer } from 'mobx-react-lite';
1413

1514
import * as Animatable from 'react-native-animatable';
@@ -20,8 +19,6 @@ import { ActionSheet } from 'teaset';
2019
import * as ImagePicker from 'react-native-image-picker';
2120

2221
import type { NavigationScreenProp } from 'react-navigation';
23-
// import { PublicStore } from '../../store/PublicStore';
24-
// import { ConfigStore } from '../../store/ConfigStore';
2522
import { StoreContext } from '../../utils/Tool';
2623

2724
type Props = {
@@ -32,7 +29,6 @@ ActionSheet.ActionSheetView.Item = PopoverActionSheetItem;
3229

3330
function selectedImagePicker(type: string, callBack: Function) {
3431
ActionSheet.hide();
35-
3632
const options = {
3733
quality: 0.5,
3834
allowsEditing: false,
@@ -72,9 +68,15 @@ function openImagePicker(imageResponse) {
7268
const ShiTu = observer((props: Props) => {
7369
const store = useContext(StoreContext);
7470

75-
const { uploadImage, getSearchDetail, backgroundImageUrl, getBackgroundImageUrl } = store.shiTuStore;
71+
const {
72+
uploadImage,
73+
getSearchDetail,
74+
backgroundImageUrl,
75+
getBackgroundImageUrl,
76+
showLoading,
77+
hideLoading
78+
} = store.shiTuStore;
7679

77-
const { showLoading, hideLoading } = store.configStore;
7880
const { navigation } = props;
7981

8082
function openImagePickerAndHandleImageData() {

app/pages/Theme/index.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @flow
3+
* Created by Rabbit on 2019-04-29.
4+
*/
5+
import React, { useContext, useState } from 'react';
6+
import { StyleSheet } from 'react-native';
7+
import BaseContainer from '../../components/BaseContainer';
8+
import { Button } from '../../components';
9+
import { StoreContext } from '../../utils/Tool';
10+
import DefaultTheme from '../../resource/thems/DefaultTheme';
11+
import CustomTheme from '../../resource/thems/CustomTheme';
12+
13+
export const ThemeScreen = (props: any) => {
14+
const store = useContext(StoreContext);
15+
const { themeStore } = store;
16+
17+
const [state, setState] = useState();
18+
19+
const backgroundColor = themeStore.themes.buttonColor;
20+
const labelColor = themeStore.themes.labelColor;
21+
22+
return (
23+
<BaseContainer
24+
style={styles.container}
25+
backButtonPress={() => {
26+
props.navigation.goBack();
27+
props.navigation.navigate('ShiTu');
28+
}}
29+
>
30+
<Button
31+
title={'更换黑色主题'}
32+
style={[styles.buttonStyle, { backgroundColor }]}
33+
titleStyle={{ color: labelColor }}
34+
onPress={() => {
35+
themeStore.setBlackTheme();
36+
setState({ state });
37+
}}
38+
/>
39+
<Button
40+
title={'更换蓝色主题'}
41+
style={[styles.buttonStyle, { backgroundColor }]}
42+
titleStyle={{ color: labelColor }}
43+
onPress={() => {
44+
themeStore.setThemes(DefaultTheme);
45+
setState({ state });
46+
}}
47+
/>
48+
<Button
49+
title={'更换导航栏颜色'}
50+
style={[styles.buttonStyle, { backgroundColor }]}
51+
titleStyle={{ color: labelColor }}
52+
onPress={() => {
53+
CustomTheme.navColor = 'green';
54+
themeStore.setThemes(CustomTheme);
55+
setState({ state });
56+
}}
57+
/>
58+
</BaseContainer>
59+
);
60+
};
61+
62+
const styles = StyleSheet.create({
63+
container: {
64+
flex: 1
65+
},
66+
buttonStyle: {
67+
height: 44,
68+
marginTop: 30,
69+
alignItems: 'center',
70+
justifyContent: 'center'
71+
}
72+
});

0 commit comments

Comments
 (0)