-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolbar.js
115 lines (107 loc) · 3.3 KB
/
toolbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* @flow
*/
'use strict';
import React from 'react';
import {
Linking,
NativeModules,
ToolbarAndroid,
} from 'react-native';
import DialogAndroid from 'react-native-dialogs';
import StatelessComponent from './StatelessComponent';
import store from './store';
import * as t from './types';
import {IList} from './types-collections';
export const TOOLBAR_HEIGHT = 56;
type ToolbarProps = {
isAutomaticNumbersEnabled: boolean,
definitionNames: IList<string>,
}
export class Toolbar extends StatelessComponent<ToolbarProps> {
actions: Array<any>;
getActions() {
const {isAutomaticNumbersEnabled} = this.props;
return [
{
title: 'Lambda palette',
icon: require('./img/lambda.png'),
show: 'always',
onPress() {
store.dispatch(t.ToggleLambdaPalette.make());
}
},
{
title: 'Definition palette',
icon: require('./img/definition.png'),
show: 'always',
onPress() {
store.dispatch(t.ToggleDefinitionPalette.make());
}
},
{
title: 'Delete definition',
onPress: this.handleDeleteDefinition.bind(this),
},
{
title: `Automatically recognize numbers: ${
isAutomaticNumbersEnabled ? 'ON' : 'OFF'}`,
onPress() {
store.dispatch(t.ToggleAutomaticNumbers.make());
}
},
{
title: 'View demo video',
onPress() {
// TODO: Show the video in the app itself instead of going to
// YouTube.
Linking.openURL('https://www.youtube.com/watch?v=0OzpqDDniDs');
}
},
{
title: 'Dev: Show options',
onPress() {
NativeModules.DeveloperSupportModule.showDevOptionsDialog();
}
},
{
title: 'Dev: Refresh JS',
onPress() {
NativeModules.DeveloperSupportModule.reloadJs();
}
},
];
}
handleActionSelected(position: number) {
this.getActions()[position].onPress();
}
handleDeleteDefinition() {
const dialog = new DialogAndroid();
dialog.set({
title: 'Choose a definition to delete',
items: this.props.definitionNames.toArray(),
itemsCallback: (index, item) => {
store.dispatch(t.DeleteDefinition.make(item));
},
negativeText: 'Cancel'
});
dialog.show();
}
render() {
return <ToolbarAndroid
title="Lambda Calculus Playground"
actions={this.getActions()}
onActionSelected={this.handleActionSelected.bind(this)}
onStartShouldSetResponderCapture={() => true}
style={{
elevation: 4,
height: TOOLBAR_HEIGHT,
backgroundColor: '#e9eaed',
position: 'absolute',
left: 0,
right: 0,
top: 0,
}}
/>
}
}