2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-09-14 14:35:58 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule ToolbarAndroidExample
|
2015-09-14 14:35:58 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2016-11-23 05:01:36 +00:00
|
|
|
|
|
|
|
var nativeImageSource = require('nativeImageSource');
|
2015-09-14 14:35:58 +00:00
|
|
|
var {
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2017-05-06 03:50:47 +00:00
|
|
|
var RNTesterBlock = require('./RNTesterBlock');
|
|
|
|
var RNTesterPage = require('./RNTesterPage');
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-10-11 14:35:49 +00:00
|
|
|
var Switch = require('Switch');
|
2015-09-14 14:35:58 +00:00
|
|
|
var ToolbarAndroid = require('ToolbarAndroid');
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ToolbarAndroidExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static title = '<ToolbarAndroid>';
|
|
|
|
static description = 'Examples of using the Android toolbar.';
|
|
|
|
|
|
|
|
state = {
|
|
|
|
actionText: 'Example app with toolbar component',
|
|
|
|
toolbarSwitch: false,
|
|
|
|
colorProps: {
|
|
|
|
titleColor: '#3b5998',
|
|
|
|
subtitleColor: '#6a7180',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterPage title="<ToolbarAndroid>">
|
|
|
|
<RNTesterBlock title="Toolbar with title/subtitle and actions">
|
2015-09-14 14:35:58 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
actions={toolbarActions}
|
2016-11-23 05:01:36 +00:00
|
|
|
navIcon={nativeImageSource({
|
|
|
|
android: 'ic_menu_black_24dp',
|
|
|
|
width: 48,
|
|
|
|
height: 48
|
|
|
|
})}
|
2015-09-14 14:35:58 +00:00
|
|
|
onActionSelected={this._onActionSelected}
|
|
|
|
onIconClicked={() => this.setState({actionText: 'Icon clicked'})}
|
|
|
|
style={styles.toolbar}
|
|
|
|
subtitle={this.state.actionText}
|
|
|
|
title="Toolbar" />
|
|
|
|
<Text>{this.state.actionText}</Text>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with logo & custom title view (a View with Switch+Text)">
|
2015-09-14 14:35:58 +00:00
|
|
|
<ToolbarAndroid
|
2016-11-23 05:01:36 +00:00
|
|
|
logo={nativeImageSource({
|
|
|
|
android: 'launcher_icon',
|
|
|
|
width: 132,
|
|
|
|
height: 144
|
|
|
|
})}
|
2015-09-14 14:35:58 +00:00
|
|
|
style={styles.toolbar}>
|
|
|
|
<View style={{height: 56, flexDirection: 'row', alignItems: 'center'}}>
|
2016-10-11 14:35:49 +00:00
|
|
|
<Switch
|
2015-09-14 14:35:58 +00:00
|
|
|
value={this.state.toolbarSwitch}
|
|
|
|
onValueChange={(value) => this.setState({'toolbarSwitch': value})} />
|
|
|
|
<Text>{'\'Tis but a switch'}</Text>
|
|
|
|
</View>
|
|
|
|
</ToolbarAndroid>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with no icon">
|
2015-09-14 14:35:58 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
actions={toolbarActions}
|
|
|
|
style={styles.toolbar}
|
|
|
|
subtitle="There be no icon here" />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with navIcon & logo, no title">
|
2015-09-14 14:35:58 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
actions={toolbarActions}
|
2016-11-23 05:01:36 +00:00
|
|
|
logo={nativeImageSource({
|
|
|
|
android: 'launcher_icon',
|
|
|
|
width: 132,
|
|
|
|
height: 144
|
|
|
|
})}
|
|
|
|
navIcon={nativeImageSource({
|
|
|
|
android: 'ic_menu_black_24dp',
|
|
|
|
width: 48,
|
|
|
|
height: 48
|
|
|
|
})}
|
2015-09-14 14:35:58 +00:00
|
|
|
style={styles.toolbar} />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with custom title colors">
|
2015-09-14 14:35:58 +00:00
|
|
|
<ToolbarAndroid
|
2016-11-23 05:01:36 +00:00
|
|
|
navIcon={nativeImageSource({
|
|
|
|
android: 'ic_menu_black_24dp',
|
|
|
|
width: 48,
|
|
|
|
height: 48
|
|
|
|
})}
|
2015-09-14 14:35:58 +00:00
|
|
|
onIconClicked={() => this.setState({colorProps: {}})}
|
|
|
|
title="Wow, such toolbar"
|
|
|
|
style={styles.toolbar}
|
|
|
|
subtitle="Much native"
|
|
|
|
{...this.state.colorProps} />
|
|
|
|
<Text>
|
|
|
|
Touch the icon to reset the custom colors to the default (theme-provided) ones.
|
|
|
|
</Text>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with remote logo & navIcon">
|
2015-09-30 12:31:30 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
actions={[{title: 'Bunny', icon: require('./bunny.png'), show: 'always'}]}
|
|
|
|
logo={require('./hawk.png')}
|
|
|
|
navIcon={require('./bunny.png')}
|
|
|
|
title="Bunny and Hawk"
|
|
|
|
style={styles.toolbar} />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
<RNTesterBlock title="Toolbar with custom overflowIcon">
|
2015-10-22 11:40:21 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
actions={toolbarActions}
|
|
|
|
overflowIcon={require('./bunny.png')}
|
|
|
|
style={styles.toolbar} />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
</RNTesterPage>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_onActionSelected = (position) => {
|
2015-09-14 14:35:58 +00:00
|
|
|
this.setState({
|
|
|
|
actionText: 'Selected ' + toolbarActions[position].title,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
var toolbarActions = [
|
2016-11-23 05:01:36 +00:00
|
|
|
{title: 'Create', icon: nativeImageSource({
|
|
|
|
android: 'ic_create_black_48dp',
|
|
|
|
width: 96,
|
|
|
|
height: 96
|
|
|
|
}), show: 'always'},
|
2015-09-14 14:35:58 +00:00
|
|
|
{title: 'Filter'},
|
2016-11-23 05:01:36 +00:00
|
|
|
{title: 'Settings', icon: nativeImageSource({
|
|
|
|
android: 'ic_settings_black_48dp',
|
|
|
|
width: 96,
|
|
|
|
height: 96
|
|
|
|
}), show: 'always'},
|
2015-09-14 14:35:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
toolbar: {
|
|
|
|
backgroundColor: '#e9eaed',
|
|
|
|
height: 56,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ToolbarAndroidExample;
|