Skip to content

Commit 0587af0

Browse files
Add
1 parent 10a7b0e commit 0587af0

File tree

6 files changed

+285
-1
lines changed

6 files changed

+285
-1
lines changed

src/App.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import ProgressBarAndroidDemo from './pages/components/ProgressBarAndroidDemo'
3131
import RefreshControlDemo from './pages/components/RefreshControlDemo'
3232
import SegmentedControlIOSDemo from './pages/components/SegmentedControlIOSDemo'
3333
import TabBarIOSDemo from './pages/components/TabBarIOSDemo'
34-
34+
import ToolbarAndroidDemo from './pages/components/ToolbarAndroidDemo'
35+
import ViewPagerAndroidDemo from './pages/components/ViewPagerAndroidDemo'
36+
import ActionSheetIOSDemo from './pages/api/ActionSheetIOSDemo'
37+
import AdSupportIOSDemo from './pages/api/AdSupportIOSDemo'
3538

3639
export default App = StackNavigator({
3740
Main: {screen: MainPage,},
@@ -58,6 +61,10 @@ export default App = StackNavigator({
5861
RefreshControl:{screen: RefreshControlDemo,},
5962
SegmentedControlIOS:{screen: SegmentedControlIOSDemo,},
6063
TabBarIOS:{screen: TabBarIOSDemo,},
64+
ToolbarAndroid:{screen: ToolbarAndroidDemo,},
65+
ViewPagerAndroid:{screen: ViewPagerAndroidDemo,},
66+
ActionSheetIOS:{screen: ActionSheetIOSDemo,},
67+
AdSupportIOS:{screen: AdSupportIOSDemo,},
6168
},
6269
{
6370
// initialRouteName: 'Profile', // 默认显示界面

src/pages/MainPage.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export default class MainPage extends Component {
1717
};
1818
sections = [
1919
{
20+
key:'API',data:[
21+
{content: 'ActionSheetIOS',},
22+
{content: 'AdSupportIOS',},
23+
],
24+
},
25+
{
26+
2027
key: 'Components', data: [
28+
{content: 'ViewPagerAndroid',},
29+
{content: 'ToolbarAndroid',},
2130
{content: 'TabBarIOS',},
2231
{content: 'SegmentedControlIOS',},
2332
{content: 'RefreshControl',},

src/pages/api/ActionSheetIOSDemo.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Created by mengqingdong on 2017/5/23.
3+
*/
4+
import React, {Component} from 'react';
5+
import {
6+
StyleSheet,
7+
View,
8+
ActionSheetIOS,
9+
Button,
10+
Alert,
11+
} from 'react-native';
12+
13+
export default class ActionSheetIOSDemo extends Component {
14+
15+
static navigationOptions = {
16+
title: 'ActionSheetIOS',
17+
};
18+
19+
_onPress = ()=>{
20+
ActionSheetIOS.showActionSheetWithOptions({
21+
options:['option1','option2','取消','删除'],
22+
cancelButtonIndex:2,
23+
destructiveButtonIndex:3,
24+
title:'title',
25+
message:'message',
26+
},(index)=>{
27+
Alert.alert('选中:'+index);
28+
})
29+
}
30+
31+
_onPress1 = ()=>{
32+
ActionSheetIOS.showShareActionSheetWithOptions({
33+
message:'message',
34+
url:'http://blog.csdn.net/mengks1987',
35+
subject:'subject',
36+
title:'title',
37+
message:'message',
38+
},()=>{
39+
40+
},()=>{
41+
42+
})
43+
}
44+
45+
render() {
46+
return (
47+
<View style={{flex:1}}>
48+
<Button title='弹出' onPress={this._onPress}/>
49+
<Button title='弹出分享' onPress={this._onPress1}/>
50+
</View>
51+
);
52+
}
53+
}

src/pages/api/AdSupportIOSDemo.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Created by mengqingdong on 2017/5/23.
3+
*/
4+
import React, {Component} from 'react';
5+
import {
6+
StyleSheet,
7+
View,
8+
Text,
9+
AdSupportIOS,
10+
} from 'react-native';
11+
12+
export default class AdSupportIOSDemo extends Component {
13+
14+
static navigationOptions = {
15+
title: 'AdSupportIOS',
16+
};
17+
18+
state = {
19+
deviceID: '0',
20+
hasAdvertiserTracking: '0',
21+
};
22+
23+
componentDidMount() {
24+
AdSupportIOS.getAdvertisingId(
25+
this._onDeviceIDSuccess,
26+
this._onDeviceIDFailure
27+
);
28+
29+
AdSupportIOS.getAdvertisingTrackingEnabled(
30+
this._onHasTrackingSuccess,
31+
this._onHasTrackingFailure
32+
);
33+
}
34+
35+
_onHasTrackingSuccess = (hasTracking) => {
36+
this.setState({
37+
'hasAdvertiserTracking': hasTracking,
38+
});
39+
};
40+
41+
_onHasTrackingFailure = (e) => {
42+
this.setState({
43+
'hasAdvertiserTracking': 'Error!',
44+
});
45+
};
46+
47+
_onDeviceIDSuccess = (deviceID) => {
48+
this.setState({
49+
'deviceID': deviceID,
50+
});
51+
};
52+
53+
_onDeviceIDFailure = (e) => {
54+
this.setState({
55+
'deviceID': 'Error!',
56+
});
57+
};
58+
59+
render() {
60+
return (
61+
<View>
62+
<Text>
63+
<Text style={styles.title}>Advertising ID: </Text>
64+
{JSON.stringify(this.state.deviceID)}
65+
</Text>
66+
<Text>
67+
<Text style={styles.title}>Has Advertiser Tracking: </Text>
68+
{JSON.stringify(this.state.hasAdvertiserTracking)}
69+
</Text>
70+
</View>
71+
);
72+
}
73+
}
74+
75+
var styles = StyleSheet.create({
76+
title: {
77+
fontWeight: '500',
78+
},
79+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Created by mengqingdong on 2017/5/23.
3+
*/
4+
import React, {Component} from 'react';
5+
import {
6+
StyleSheet,
7+
View,
8+
ToolbarAndroid,
9+
} from 'react-native';
10+
11+
export default class ToolbarAndroidDemo extends Component {
12+
13+
static navigationOptions = {
14+
title: 'ToolbarAndroid',
15+
};
16+
17+
_onActionSelected = (position) => {
18+
if (position === 0) {
19+
20+
}
21+
}
22+
23+
render() {
24+
return (
25+
<ToolbarAndroid
26+
style={{height:55,backgroundColor:'red'}}
27+
logo={require('../../imgs/icon1.png')}
28+
title='TITLE'
29+
actions={[{title: 'Settings', icon: require('../../imgs/back.png'), show: 'always'}]}
30+
onActionSelected={this._onActionSelected}
31+
contentInsetEnd={25}
32+
contentInsetStart={25}
33+
navIcon={require('../../imgs/icon1.png')}/>
34+
);
35+
}
36+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Created by mengqingdong on 2017/5/23.
3+
*/
4+
import React, {Component} from 'react';
5+
import {
6+
StyleSheet,
7+
View,
8+
ViewPagerAndroid,
9+
Text,
10+
} from 'react-native';
11+
12+
export default class ViewPagerAndroidDemo extends Component {
13+
14+
static navigationOptions = {
15+
title: 'ViewPagerAndroid',
16+
};
17+
state = {
18+
position: 0,
19+
offset: 0,
20+
onPageScrollState:0,
21+
onPageSelectedIndex:0,
22+
}
23+
_viewPage;
24+
componentDidMount(){
25+
setInterval(()=>{
26+
if(this.state.onPageSelectedIndex>=4){
27+
this.setState({
28+
onPageSelectedIndex:0,
29+
});
30+
}else{
31+
this.setState({
32+
onPageSelectedIndex:this.state.onPageSelectedIndex+1,
33+
});
34+
}
35+
this._viewPage.setPage(this.state.onPageSelectedIndex);
36+
},2000)
37+
}
38+
39+
_onPageScroll = (event) => {
40+
this.setState({
41+
position: event.nativeEvent.position,
42+
offset: event.nativeEvent.offset,
43+
});
44+
}
45+
46+
_onPageScrollStateChanged = (value)=>{
47+
this.setState({
48+
onPageScrollState:value,
49+
});
50+
}
51+
52+
_onPageSelected=(event)=>{
53+
this.setState({
54+
onPageSelectedIndex:event.nativeEvent.position,
55+
});
56+
}
57+
58+
render() {
59+
return (
60+
<View style={{flex:1}}>
61+
<Text>position:{this.state.position}offset:{this.state.offset}</Text>
62+
<Text>onPageScrollState:{this.state.onPageScrollState}</Text>
63+
<Text>onPageSelectedIndex:{this.state.onPageSelectedIndex}</Text>
64+
<ViewPagerAndroid
65+
ref={(viewPager)=>this._viewPage = viewPager}
66+
style={{flex:1}}
67+
initialPage={0}
68+
onPageScroll={this._onPageScroll}
69+
scrollEnabled={true}
70+
onPageScrollStateChanged={this._onPageScrollStateChanged}
71+
onPageSelected={this._onPageSelected}>
72+
73+
<View style={[styles.pageStyle,{backgroundColor:'red'}]}>
74+
<Text>1</Text>
75+
</View>
76+
<View style={[styles.pageStyle,{backgroundColor:'blue'}]}>
77+
<Text>2</Text>
78+
</View>
79+
<View style={[styles.pageStyle,{backgroundColor:'green'}]}>
80+
<Text>3</Text>
81+
</View>
82+
<View style={[styles.pageStyle,{backgroundColor:'white'}]}>
83+
<Text>4</Text>
84+
</View>
85+
<View style={[styles.pageStyle,{backgroundColor:'yellow'}]}>
86+
<Text>5</Text>
87+
</View>
88+
89+
</ViewPagerAndroid >
90+
</View>
91+
);
92+
}
93+
}
94+
95+
const styles = StyleSheet.create({
96+
pageStyle: {
97+
alignItems: 'center',
98+
justifyContent: 'center'
99+
}
100+
})

0 commit comments

Comments
 (0)