forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReaderDisplayOptionsMenu.js
309 lines (288 loc) · 12.1 KB
/
ReaderDisplayOptionsMenu.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
'use strict';
import PropTypes from 'prop-types';
import React from 'react';
import {
Text,
TouchableOpacity,
View,
Image,
Animated,
} from 'react-native';
import styles from './Styles.js';
import strings from './LocalizedStrings';
import { VOCALIZATION } from './VocalizationEnum';
var a_aleph_icon = require('./img/a_aleph.png');
var a_icon = require('./img/a_icon.png');
var a_icon_small = require('./img/a_icon_small.png');
var aleph_icon = require('./img/aleph.png');
var segmented_icon = require('./img/breaks.png');
var continuous_icon = require('./img/continuous.png');
var stacked_icon = require('./img/stacked.png');
var side_icon = require('./img/sidebyside.png');
var siderev_icon = require('./img/sidebysiderev.png');
var a_aleph_icon_light = require('./img/a_aleph-light.png');
var a_icon_light = require('./img/a_icon-light.png');
var a_icon_small_light = require('./img/a_icon_small-light.png');
var aleph_icon_light = require('./img/aleph-light.png');
var segmented_icon_light = require('./img/breaks-light.png');
var continuous_icon_light = require('./img/continuous-light.png');
var stacked_icon_light = require('./img/stacked-light.png');
var side_icon_light = require('./img/sidebyside-light.png');
var siderev_icon_light = require('./img/sidebysiderev-light.png');
class ReaderDisplayOptionsMenu extends React.Component {
static whyDidYouRender = true;
static propTypes = {
theme: PropTypes.object,
textFlow: PropTypes.oneOf(['segmented', 'continuous']),
canHaveAliyot: PropTypes.bool.isRequired,
canBeContinuous: PropTypes.bool.isRequired,
vowelToggleAvailable: PropTypes.oneOf([VOCALIZATION.TAAMIM_AND_NIKKUD, VOCALIZATION.NIKKUD, VOCALIZATION.NONE]),
interfaceLanguage: PropTypes.oneOf(['hebrew', 'english']).isRequired,
textLanguage: PropTypes.oneOf(['hebrew', 'english', 'bilingual']),
themeStr: PropTypes.oneOf(['white', 'black']),
showAliyot: PropTypes.bool.isRequired,
setTextFlow: PropTypes.func,
setTextLanguage: PropTypes.func,
setAliyot: PropTypes.func,
incrementFont: PropTypes.func,
setTheme: PropTypes.func
};
constructor(props) {
super(props);
this._position = new Animated.Value(0);
}
show = () => {
Animated.timing(this._position, {
toValue: 1,
duration: 250,
useNativeDriver: false,
}).start();
};
hide = (cb) => {
Animated.timing(this._position, {
toValue: 0,
duration: 250,
useNativeDriver: false,
}).start(cb);
};
render() {
const options = [
{
label: strings.languageYo,
onPress: this.props.setTextLanguage,
buttons: ["english","bilingual","hebrew"],
icons: this.props.themeStr == "white" ? [a_icon,a_aleph_icon,aleph_icon]: [a_icon_light,a_aleph_icon_light,aleph_icon_light],
currVal: this.props.textLanguage,
parametrized: true
},
{
condition: this.props.canBeContinuous,
label: strings.layout,
onPress: this.props.setTextFlow,
buttons: ["segmented","continuous"],
icons: this.props.themeStr == "white" ? [segmented_icon,continuous_icon]: [segmented_icon_light,continuous_icon_light],
currVal: this.props.textFlow,
parametrized: true
},
{
condition: this.props.textLanguage === 'bilingual',
label: strings.bilingualLayout,
onPress: this.props.setBiLayout,
buttons: ["stacked", "sidebyside", "sidebysiderev"],
icons: this.props.themeStr == "white" ? [stacked_icon,side_icon,siderev_icon] : [stacked_icon_light,side_icon_light,siderev_icon_light],
currVal: this.props.biLayout,
parametrized: true,
iconLength: 19,
},
{
label: strings.color,
onPress: this.props.setTheme,
buttons:["white","black"],
colors:["#ffffff", "#444444"],
currVal: this.props.themeStr,
parametrized: true
},
{
condition: this.props.canHaveAliyot,
label: strings.aliyot,
onPress: this.props.setAliyot,
buttons:[true, false],
text: [strings.on, strings.off],
currVal: this.props.showAliyot,
parametrized: true,
},
{
label: strings.fontSize,
onPress: this.props.incrementFont,
buttons:["smaller","larger"],
icons: this.props.themeStr == "white" ? [a_icon_small,a_icon]: [a_icon_small_light,a_icon_light],
currVal: null,
parametrized: true
},
{
condition: this.props.vowelToggleAvailable < VOCALIZATION.NONE,
label: this.props.vowelToggleAvailable === VOCALIZATION.TAAMIM_AND_NIKKUD ? strings.vocalization : strings.vowels,
onPress: this.props.setVocalization,
buttons:[VOCALIZATION.TAAMIM_AND_NIKKUD, VOCALIZATION.NIKKUD, VOCALIZATION.NONE].slice(this.props.vowelToggleAvailable),
text: ["אָ֑", "אָ", "א"].slice(this.props.vowelToggleAvailable),
textStyle: [styles.he, {fontSize: 26}],
currVal: Math.max(this.props.vocalization, this.props.vowelToggleAvailable),
parametrized: true,
},
];
const alignments = [["left","right"],["left","center","right"]];
let toggleSets = []; // two toggle sets per row
const rows = [];
for (let j = 0; j < options.length; j++) {
let optionRow = options[j];
if (typeof optionRow.condition !== 'undefined' && !optionRow.condition) { continue; }
let row = [];
let isColor = "colors" in optionRow;
for (let i = 0; i < optionRow.buttons.length; i++) {
let option = optionRow.buttons[i];
let selected = optionRow.currVal === option;
if (isColor) {
let color = optionRow.colors[i];
row.push(
<ReaderDisplayOptionsMenuColor
key={option}
theme={this.props.theme}
option={option}
onPress={optionRow.onPress}
parametrized={optionRow.parametrized}
color={color}
align={alignments[optionRow.buttons.length-2][i]}
selected={selected} />
);
} else {
const icon = !!optionRow.icons ? optionRow.icons[i] : null;
const text = !!optionRow.text ? optionRow.text[i] : null;
row.push(
<ReaderDisplayOptionsMenuItem
key={option}
theme={this.props.theme}
option={option}
onPress={optionRow.onPress}
parametrized={optionRow.parametrized}
icon={icon}
iconLength={optionRow.iconLength}
text={text}
textStyle={optionRow.textStyle}
align={alignments[optionRow.buttons.length-2][i]}
selected={selected}
interfaceLanguage={this.props.interfaceLanguage} />
);
}
}
toggleSets.push(<ReaderDisplayOptionsMenuToggleSet key={optionRow.label + "|toggleSet"} label={optionRow.label} content={row} colorRow={isColor} theme={this.props.theme} interfaceLanguage={this.props.interfaceLanguage}/>);
if (toggleSets.length % 2 === 0 || j === options.length - 1) {
rows.push(<ReaderDisplayOptionsMenuRow key={optionRow.label + "|row"} content={toggleSets.slice(0)} />);
toggleSets = [];
}
}
const myStyles = [
styles.readerDisplayOptionsMenu,
this.props.theme.readerDisplayOptionsMenu,
{
top: this._position.interpolate({
inputRange: [0, 1],
outputRange: [-350, 0],
extrapolate: 'clamp',
}),
},
];
return (
<View style={styles.readerDisplayOptionsMenuMask}>
<Animated.View style={myStyles}>
{rows}
</Animated.View>
</View>
);
}
}
class ReaderDisplayOptionsMenuRow extends React.Component {
render() {
return (<View style={styles.readerDisplayOptionsMenuRow}>
{this.props.content}
</View>);
}
}
class ReaderDisplayOptionsMenuToggleSet extends React.Component {
render() {
//styles.readerDisplayOptionMenuRowNotColor is a hack required to solve the problem of react native / ios display not yet properly rendering borderRadius & borderWidth w/o 'smearing'
const tempStyles = this.props.colorRow ? [styles.readerDisplayOptionsMenuToggleSet] : [styles.readerDisplayOptionsMenuToggleSet,styles.readerDisplayOptionMenuToggleSetNotColor,this.props.theme.readerDisplayOptionsMenuDivider];
const langStyle = this.props.interfaceLanguage === "hebrew" ? styles.heInt : styles.enInt;
return (
<View style={styles.readerDisplayOptionsMenuToggleSetOuter}>
<Text style={[langStyle, {textAlign: "center"}, this.props.theme.secondaryText]}>{this.props.label}</Text>
<View style={tempStyles}>
{this.props.content}
</View>
</View>
);
}
}
class ReaderDisplayOptionsMenuItem extends React.Component {
static propTypes = {
theme: PropTypes.object,
option: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
icon: PropTypes.number, /*PTP: why are images numbers? */
iconLength: PropTypes.number,
text: PropTypes.string,
textStyle: PropTypes.array,
align: PropTypes.string,
onPress: PropTypes.func.isRequired,
parametrized: PropTypes.bool, /* should onPress() use option as a paremeter*/
selected: PropTypes.bool
};
render() {
const langStyle = this.props.interfaceLanguage === "hebrew" ? styles.heInt : styles.enInt;
let alignStyle;
if (this.props.align == "right") alignStyle = styles.readerDisplayOptionsMenuItemRight;
else if (this.props.align == "left") alignStyle = styles.readerDisplayOptionsMenuItemLeft;
else /*if (this.props.align == "center") */ alignStyle = styles.readerDisplayOptionsMenuItemCenter;
var onPress = this.props.parametrized ? (()=>this.props.onPress(this.props.option)) : this.props.onPress;
var tempStyles = [styles.readerDisplayOptionsMenuItem, this.props.theme.readerDisplayOptionsMenuItem, alignStyle];
if (this.props.selected) {
tempStyles.push(this.props.theme.readerDisplayOptionsMenuItemSelected);
}
const iconStyles = [styles.readerDisplayOptionsMenuIcon];
if (this.props.iconLength) {
iconStyles.push({width: this.props.iconLength, height: this.props.iconLength});
}
return (
<TouchableOpacity onPress={onPress} style={tempStyles}>
{this.props.icon ?
<Image resizeMode={'contain'} style={iconStyles} source={this.props.icon}/> :
<Text style={[langStyle, this.props.theme.secondaryText].concat(this.props.textStyle)}>{this.props.text}</Text>
}
</TouchableOpacity>
);
}
}
class ReaderDisplayOptionsMenuColor extends React.Component {
static propTypes = {
theme: PropTypes.object,
option: PropTypes.string,
color: PropTypes.string,
align: PropTypes.string,
onPress: PropTypes.func.isRequired,
parametrized: PropTypes.bool, /* should onPress() use option as a paremeter*/
selected: PropTypes.bool
};
render() {
let alignStyle;
if (this.props.align == "right") alignStyle = styles.readerDisplayOptionsMenuColorRight;
else if (this.props.align == "left") alignStyle = styles.readerDisplayOptionsMenuColorLeft;
else /*if (this.props.align == "center") */ alignStyle = styles.readerDisplayOptionsMenuColorCenter;
var onPress = this.props.parametrized ? (()=>this.props.onPress(this.props.option)) : this.props.onPress;
var tempStyles = [styles.readerDisplayOptionsMenuColor, this.props.theme.readerDisplayOptionsMenuColor, {"backgroundColor": this.props.color}, alignStyle];
if (this.props.selected) {
tempStyles.push(styles.readerDisplayOptionsMenuColorSelected);
}
return (
<TouchableOpacity onPress={onPress} style={tempStyles}/>
);
}
}
export default ReaderDisplayOptionsMenu;