Skip to content

Commit 95c46b8

Browse files
Make text input and the android toolbar cross platform
1 parent c63b122 commit 95c46b8

File tree

4 files changed

+86
-24
lines changed

4 files changed

+86
-24
lines changed

ios/GooglePlayMusicDesktopRemote/DeviceInfo.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,46 @@
66
// Copyright © 2016 Samuel Attard. All rights reserved.
77
//
88

9+
#import "RCTBridge.h"
10+
#import "RCTEventDispatcher.h"
911
#import "DeviceInfo.h"
1012

1113
@implementation DeviceInfo
14+
@synthesize bridge = _bridge;
15+
16+
- (dispatch_queue_t)methodQueue
17+
{
18+
return dispatch_get_main_queue();
19+
}
20+
21+
-(void) dealloc{
22+
[[NSNotificationCenter defaultCenter] removeObserver: self];
23+
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
24+
}
25+
26+
- (void)deviceOrientationDidChange:(NSNotification *)notification
27+
{
28+
NSString *oN = @"PORTRAIT";
29+
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
30+
31+
if(orientation == 0) //Default orientation
32+
oN = @"PORTRAIT";
33+
else if(orientation == UIInterfaceOrientationPortrait)
34+
oN = @"PORTRAIT";
35+
else if(orientation == UIInterfaceOrientationLandscapeLeft)
36+
oN = @"LANDSCAPE";
37+
else if(orientation == UIInterfaceOrientationLandscapeRight)
38+
oN = @"LANDSCAPE";
39+
40+
[self.bridge.eventDispatcher sendAppEventWithName:@"orientation"
41+
body:@{@"orientation": oN}];
42+
}
1243

1344
RCT_REMAP_METHOD(getDeviceOrientation, resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
1445
{
46+
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
47+
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
48+
1549
NSString *oN = @"1";
1650
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
1751

@@ -31,6 +65,7 @@ @implementation DeviceInfo
3165
resolve([[UIDevice currentDevice] name]);
3266
}
3367

68+
3469
RCT_EXPORT_MODULE();
3570

3671
@end

src/components/Toolbar.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component, PropTypes } from 'react'
2-
import { StyleSheet } from 'react-native'
2+
import { Platform, TabBarIOS, StyleSheet, View, Text, TouchableOpacity } from 'react-native'
33
import Icon from 'react-native-vector-icons/Ionicons'
44
import colors from '../theme/colors'
55

@@ -48,23 +48,47 @@ export default class Toolbar extends Component {
4848
}
4949
]
5050

51+
if (Platform.OS === 'android') {
52+
return (
53+
<Icon.ToolbarAndroid
54+
navIconName={showDrawer ? 'md-menu' : 'md-arrow-back'}
55+
onIconClicked={showDrawer ? drawerFunction : this._backButtonPressed}
56+
style={[styles.toolbar, { backgroundColor: color }]}
57+
titleColor={'white'}
58+
title={title}
59+
actions={(settingsMenu ? actions : null)}
60+
onActionSelected={this._actionSelected}
61+
/>
62+
)
63+
}
64+
const search = settingsMenu ? (
65+
<TouchableOpacity onPress={() => this.props.navigator.push({ name: 'search' })}>
66+
<Icon color="white" size={22} name="md-search" style={{ flex: 0, marginLeft: 14, width: 24 }} />
67+
</TouchableOpacity>
68+
) : null
69+
const settings = settingsMenu ? (
70+
<TouchableOpacity onPress={() => this.props.navigator.push({ name: 'settings' })}>
71+
<Icon color="white" size={22} name="md-settings" style={{ flex: 0, marginHorizontal: 14, width: 24 }} />
72+
</TouchableOpacity>
73+
) : null
5174
return (
52-
<Icon.ToolbarAndroid
53-
navIconName={showDrawer ? 'md-menu' : 'md-arrow-back'}
54-
onIconClicked={showDrawer ? drawerFunction : this._backButtonPressed}
55-
style={[styles.toolbar, { backgroundColor: color }]}
56-
titleColor={'white'}
57-
title={title}
58-
actions={(settingsMenu ? actions : null)}
59-
onActionSelected={this._actionSelected}
60-
/>
75+
<View style={[styles.toolbar, { backgroundColor: color, paddingTop: 22 }]}>
76+
<TouchableOpacity onPress={showDrawer ? drawerFunction : this._backButtonPressed}>
77+
<Icon color="white" size={22} name={showDrawer ? 'md-menu' : 'md-arrow-back'} style={{ flex: 0, marginLeft: 14, width: 24 }} />
78+
</TouchableOpacity>
79+
<Text style={{ color: 'white', marginLeft: 8, fontSize: 22, flex: 1 }}>{title}</Text>
80+
{search}
81+
{settings}
82+
</View>
6183
)
6284
}
6385
}
6486

6587
const styles = StyleSheet.create({
6688
toolbar: {
6789
height: 56,
68-
elevation: 2
90+
elevation: 2,
91+
flexDirection: 'row',
92+
alignItems: 'flex-start'
6993
}
7094
})

src/screens/SearchScreen.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component, PropTypes } from 'react'
2-
import { ScrollView, StatusBar, StyleSheet, TextInput, View } from 'react-native'
2+
import { ScrollView, StatusBar, StyleSheet, Text, TextInput, View } from 'react-native'
3+
import { MKTextField } from 'react-native-material-kit'
34
import { observer } from 'mobx-react/native'
45
import Toolbar from '../components/Toolbar'
56
import ScrollableTabView, { DefaultTabBar } from 'react-native-scrollable-tab-view'
@@ -47,16 +48,19 @@ export default class SearchScreen extends Component {
4748
<Toolbar title={'Search'} navigator={this.props.navigator} color={themeStore.barColor()} />
4849
<View style={styles.content}>
4950
<View style={styles.settingsContent}>
50-
<TextInput
51-
style={{ color: themeStore.foreColor() }}
51+
<MKTextField
52+
textInputStyle={{ color: themeStore.foreColor() }}
5253
autoCorrect={true}
5354
defaultValue={searchStore.searchText}
5455
keyboardType="web-search"
55-
underlineColorAndroid={themeStore.highlightColor()}
56+
underlineEnabled
57+
underlineSize={2}
58+
highlightColor={themeStore.highlightColor()}
5659
placeholder="Search text here..."
5760
placeholderTextColor={themeStore.foreColor()}
5861
onChangeText={this._updateSearchText}
5962
onSubmitEditing={this._search}
63+
tintColor="#999"
6064
/>
6165
</View>
6266
<ScrollableTabView

src/screens/SettingsScreen.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import React, { Component, PropTypes } from 'react'
2-
import { AsyncStorage, StatusBar, StyleSheet, Text, TextInput, View } from 'react-native'
2+
import { StatusBar, StyleSheet, Text, View } from 'react-native'
33
import { observer } from 'mobx-react/native'
4-
import { getTheme } from 'react-native-material-kit'
4+
import { MKTextField } from 'react-native-material-kit'
55
// import Zeroconf from 'react-native-zeroconf'
66
import Toolbar from '../components/Toolbar'
7-
import colors from '../theme/colors'
8-
9-
const theme = getTheme()
107

118
@observer
129
export default class SettingsScreen extends Component {
@@ -29,15 +26,17 @@ export default class SettingsScreen extends Component {
2926
<View style={styles.content}>
3027
<View style={styles.settingsContent}>
3128
<Text style={{ color: themeStore.foreColor() }}>GPMDP IP Address</Text>
32-
<TextInput
33-
style={{ color: themeStore.foreColor() }}
34-
autoCorrect={false}
29+
<MKTextField
30+
textInputStyle={{ color: themeStore.foreColor() }}
3531
defaultValue={this.props.settingsStore.IP_ADDRESS === 'NOT_SET' ? '' : this.props.settingsStore.IP_ADDRESS}
3632
keyboardType="numeric"
37-
underlineColorAndroid={themeStore.highlightColor()}
33+
underlineEnabled
34+
underlineSize={2}
35+
highlightColor={themeStore.highlightColor()}
3836
placeholder="GPMDP IP Address"
3937
placeholderTextColor={themeStore.foreColor()}
4038
onChangeText={this._ipChanged}
39+
tintColor="#999"
4140
/>
4241
</View>
4342
</View>

0 commit comments

Comments
 (0)