-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMentionStyleProps.mm
More file actions
80 lines (67 loc) · 2.85 KB
/
Copy pathMentionStyleProps.mm
File metadata and controls
80 lines (67 loc) · 2.85 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "MentionStyleProps.h"
#import "extensions/StringExtension.h"
#import <React/RCTConversions.h>
@implementation MentionStyleProps
+ (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic:
(folly::dynamic)folly {
MentionStyleProps *nativeProps = [[MentionStyleProps alloc] init];
if (folly["color"].isNumber()) {
facebook::react::SharedColor color = facebook::react::SharedColor(
facebook::react::Color(int32_t(folly["color"].asInt())));
nativeProps.color = RCTUIColorFromSharedColor(color);
} else {
nativeProps.color = [UIColor blueColor];
}
if (folly["backgroundColor"].isNumber()) {
facebook::react::SharedColor bgColor = facebook::react::SharedColor(
facebook::react::Color(int32_t(folly["backgroundColor"].asInt())));
nativeProps.backgroundColor = RCTUIColorFromSharedColor(bgColor);
} else {
nativeProps.backgroundColor = [UIColor yellowColor];
}
if (folly["textDecorationLine"].isString()) {
std::string textDecorationLine = folly["textDecorationLine"].asString();
nativeProps.decorationLine = [[NSString fromCppString:textDecorationLine]
isEqualToString:DecorationUnderline]
? DecorationUnderline
: DecorationNone;
} else {
nativeProps.decorationLine = DecorationUnderline;
}
// text only
if (folly["pressColor"].isNumber()) {
facebook::react::SharedColor pressColor = facebook::react::SharedColor(
facebook::react::Color(int32_t(folly["pressColor"].asInt())));
nativeProps.pressColor = RCTUIColorFromSharedColor(pressColor);
} else {
nativeProps.pressColor = [UIColor blueColor];
}
if (folly["pressBackgroundColor"].isNumber()) {
facebook::react::SharedColor bgColor = facebook::react::SharedColor(
facebook::react::Color(int32_t(folly["pressBackgroundColor"].asInt())));
nativeProps.pressBackgroundColor = RCTUIColorFromSharedColor(bgColor);
} else {
nativeProps.pressBackgroundColor = [UIColor yellowColor];
}
return nativeProps;
}
+ (NSDictionary *)getSinglePropsFromFollyDynamic:(folly::dynamic)folly {
MentionStyleProps *nativeProps =
[MentionStyleProps getSingleMentionStylePropsFromFollyDynamic:folly];
// the single props need to be somehow distinguishable in config
NSDictionary *dict = @{@"all" : nativeProps};
return dict;
}
+ (NSDictionary *)getComplexPropsFromFollyDynamic:(folly::dynamic)folly {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
for (const auto &obj : folly.items()) {
if (obj.first.isString() && obj.second.isObject()) {
std::string key = obj.first.asString();
MentionStyleProps *props = [MentionStyleProps
getSingleMentionStylePropsFromFollyDynamic:obj.second];
dict[[NSString fromCppString:key]] = props;
}
}
return dict;
}
@end