forked from nodegui/react-nodegui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRNText.ts
More file actions
65 lines (61 loc) · 1.88 KB
/
RNText.ts
File metadata and controls
65 lines (61 loc) · 1.88 KB
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
import { QLabel, NodeWidget, QLabelSignals, TextInteractionFlag } from '@nodegui/nodegui';
import { ViewProps, setViewProps } from '../View/RNView';
import { RNWidget } from '../config';
import { throwUnsupported } from '../../utils/helpers';
export interface TextProps extends ViewProps<QLabelSignals> {
children?: string | number | Array<string | number>;
wordWrap?: boolean;
scaledContents?: boolean;
openExternalLinks?: boolean;
textInteractionFlags?: TextInteractionFlag;
}
/**
* @ignore
*/
export const setTextProps = (
widget: RNText,
newProps: TextProps,
oldProps: TextProps
) => {
const setter: TextProps = {
set children(text: string | number | Array<string | number>) {
text = Array.isArray(text) ? text.join('') : text;
widget.setText(text);
},
set wordWrap(shouldWrap: boolean) {
widget.setWordWrap(shouldWrap);
},
set scaledContents(scaled: boolean) {
widget.setProperty('scaledContents', scaled);
},
set openExternalLinks(shouldOpenExternalLinks: boolean) {
widget.setProperty('openExternalLinks', shouldOpenExternalLinks);
},
set textInteractionFlags(interactionFlag: TextInteractionFlag){
widget.setProperty('textInteractionFlags', interactionFlag);
}
};
Object.assign(setter, newProps);
setViewProps(widget, newProps, oldProps);
};
/**
* @ignore
*/
export class RNText extends QLabel implements RNWidget {
setProps(newProps: TextProps, oldProps: TextProps): void {
setTextProps(this, newProps, oldProps);
}
appendInitialChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
appendChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
throwUnsupported(this);
}
removeChild(child: NodeWidget<any>): void {
throwUnsupported(this);
}
static tagName = 'text';
}