-
Notifications
You must be signed in to change notification settings - Fork 493
/
Copy pathText.tsx
54 lines (48 loc) · 1.92 KB
/
Text.tsx
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
/**
* Text.tsx
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Android-specific implementation of Text component.
*/
import * as React from 'react';
import * as RN from 'react-native';
import AccessibilityUtil from '../native-common/AccessibilityUtil';
import { Types } from '../common/Interfaces';
import Styles from '../native-common/Styles';
import { Text as CommonText } from '../native-common/Text';
const _styles = {
defaultText: Styles.createTextStyle({
includeFontPadding: false,
textAlignVertical: 'center',
}),
};
export class Text extends CommonText {
protected _getStyles(): Types.StyleRuleSetRecursiveArray<Types.TextStyleRuleSet> {
return [_styles.defaultText, this.props.style];
}
// We override the render method to work around a couple of Android-specific
// bugs in RN. First, numberOfLines needs to be set to null rather than 0 to
// indicate an unbounded number of lines. Second, ellipsizeMode needs to be set
// to null to indicate the default behavior.
render() {
const importantForAccessibility = AccessibilityUtil.importantForAccessibilityToString(this.props.importantForAccessibility);
return (
<RN.Text
style={ this._getStyles() as RN.StyleProp<RN.TextStyle> }
ref={ this._onMount }
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? undefined : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
ellipsizeMode={ this.props.ellipsizeMode }
onPress={ this.props.onPress }
textBreakStrategy={ this.props.textBreakStrategy }
testID={ this.props.testId }
>
{ this.props.children }
</RN.Text>
);
}
}
export default Text;