-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
TextRange.js
166 lines (156 loc) · 6.67 KB
/
TextRange.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
'use strict';
import PropTypes from 'prop-types';
import React, { useContext, useCallback } from 'react';
import {
View,
Text,
Platform,
Linking,
} from 'react-native';
import { GlobalStateContext, getTheme } from './StateManager';
import TextSegment from './TextSegment';
import styles from './Styles';
import iPad from "./isIPad";
const TextRange = React.memo(({
displayRef,
showToast,
rowData,
segmentRef,
showSegmentNumbers,
textSegmentPressed,
setRowRef,
setRowRefInitY,
handleOpenURL,
setDictionaryLookup,
shareCurrentSegment,
getDisplayedText,
vowelToggleAvailable,
isSheet,
setHighlightedWord,
}) => {
const { themeStr, textLanguage, biLayout, fontSize, vocalization } = useContext(GlobalStateContext);
const theme = getTheme(themeStr);
const _setRef = ref => {
setRowRef(segmentRef, ref);
};
let enText = rowData.content.text || "";
let heText = Sefaria.util.applyVocalizationSettings(rowData.content.he, vocalization, vowelToggleAvailable) || "";
enText = Sefaria.util.getDisplayableHTML(enText, 'english', isSheet, false);
heText = Sefaria.util.getDisplayableHTML(heText, 'hebrew', isSheet, true);
let numLinks = rowData.content.links ? rowData.content.links.length : 0;
const textLanguageWithContent = Sefaria.util.getTextLanguageWithContent(textLanguage, enText, heText);
const ratiobasedFontSize = (fontSize) => {
// The sizes were taken from styles.verseNumber.fontSize/hebrewVerseNumber and StateManager.fontSize
return iPad ? 11/25*fontSize : textLanguageWithContent === "hebrew" ? 11/20*fontSize : 9/20*fontSize}
let refSection = rowData.sectionIndex + ":" + rowData.rowIndex;
let numberMargin = (<Text
style={[styles.verseNumber, theme.verseNumber, {fontSize: ratiobasedFontSize(fontSize)}]}
key={segmentRef + "|segment-number"}>
{showSegmentNumbers ? (textLanguageWithContent == "hebrew" ?
Sefaria.hebrew.encodeHebrewNumeral(rowData.content.segmentNumber) :
rowData.content.segmentNumber) : ""}
</Text>);
let bulletOpacity = (numLinks-20) / (70-20);
if (numLinks == 0) { bulletOpacity = 0; }
else if (bulletOpacity < 0.3) { bulletOpacity = 0.3; }
else if (bulletOpacity > 0.8) { bulletOpacity = 0.8; }
var bulletMargin = (<Text
style={[styles.verseBullet, theme.verseBullet, {opacity:bulletOpacity}]}
key={segmentRef + "|segment-dot"}>
{"●"}
</Text>);
let textStyle = [styles.textSegment];
if (rowData.highlight) {
textStyle.push(theme.segmentHighlight);
}
if (biLayout === 'sidebyside') {
textStyle.push({flexDirection: "row"})
} else if (biLayout === 'sidebysiderev') {
textStyle.push({flexDirection: "row-reverse"})
}
const showHe = textLanguageWithContent == "hebrew" || textLanguageWithContent == "bilingual";
const showEn = textLanguageWithContent == "english" || textLanguageWithContent == "bilingual";
const onTextPress = useCallback((onlyOpen) => {
let key = refSection;
let section = parseInt(key.split(":")[0]);
let segment = parseInt(key.split(":")[1]);
textSegmentPressed(section, segment, segmentRef, onlyOpen);
}, [refSection, segmentRef]);
return (
<View
style={styles.verseContainer}
ref={_setRef}
>
<View
style={[styles.numberSegmentHolderEn, {flexDirection: textLanguageWithContent === 'english' ? 'row' : 'row-reverse'}]}
key={segmentRef+"|inner-box"}
>
{ numberMargin }
<View style={textStyle} key={segmentRef+"|text-box"}>
{
showHe ? (
<View style={{flex: 4.5, paddingRight: biLayout == 'stacked' ? 0 : (biLayout == 'sidebyside' ? 10 : 0), paddingLeft: biLayout == 'stacked' ? 0 : (biLayout == 'sidebysiderev' ? 10 : 0)}}>
{displayRef ? <Text style={[styles.he, styles.textListCitation, {marginBottom: -10}, theme.textListCitation]}>{rowData.content.sourceHeRef}</Text> : null}
<TextSegment
fontSize={fontSize}
themeStr={themeStr}
segmentRef={segmentRef}
segmentKey={refSection}
data={heText}
textType="hebrew"
onTextPress={onTextPress}
showToast={showToast}
setDictionaryLookup={setDictionaryLookup}
handleOpenURL={handleOpenURL}
shareCurrentSegment={shareCurrentSegment}
getDisplayedText={getDisplayedText}
setHighlightedWord={setHighlightedWord}
highlightedWordID={rowData.highlightedWordID}
/>
</View>
) : null
}
{
showEn ? (
<View style={{flex: 5.5, paddingTop: showHe ? biLayout == 'stacked' ? 5 : 0 : 0, paddingRight: biLayout == 'stacked' ? 0 : (biLayout == 'sidebyside' ? 0 : 10), paddingLeft: biLayout == 'stacked' ? 0 : (biLayout == 'sidebysiderev' ? 0 : 10)}}>
{displayRef ? <Text style={[styles.en, styles.textListCitation, theme.textListCitation, {marginBottom: 0}]}>{rowData.content.sourceRef}</Text> : null}
<TextSegment
fontSize={fontSize}
themeStr={themeStr}
segmentRef={segmentRef}
segmentKey={refSection}
data={enText}
textType="english"
bilingual={textLanguageWithContent === "bilingual"}
onTextPress={onTextPress}
showToast={showToast}
setDictionaryLookup={setDictionaryLookup}
handleOpenURL={handleOpenURL}
shareCurrentSegment={shareCurrentSegment}
getDisplayedText={getDisplayedText}
setHighlightedWord={setHighlightedWord}
highlightedWordID={rowData.highlightedWordID}
/>
</View>
) : null
}
</View>
{ bulletMargin }
</View>
</View>
);
});
TextRange.whyDidYouRender = {customName: 'TextRange'};
TextRange.propTypes = {
showToast: PropTypes.func.isRequired,
rowData: PropTypes.object.isRequired,
segmentRef: PropTypes.string.isRequired,
segmentHeRef: PropTypes.string,
showSegmentNumbers: PropTypes.bool.isRequired,
textSegmentPressed: PropTypes.func.isRequired,
setRowRef: PropTypes.func.isRequired,
setRowRefInitY: PropTypes.func.isRequired,
shareCurrentSegment:PropTypes.func.isRequired,
getDisplayedText: PropTypes.func.isRequired,
};
export default TextRange;