react-native-platform-components 0.8.9 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -30
- package/android/src/main/java/com/platformcomponents/PCImageLoader.kt +88 -0
- package/android/src/main/java/com/platformcomponents/PCSegmentedControlView.kt +288 -29
- package/android/src/main/java/com/platformcomponents/PCSegmentedControlViewManager.kt +74 -8
- package/ios/PCConstants.swift +39 -3
- package/ios/PCImageLoader.swift +58 -0
- package/ios/PCSegmentedControl.mm +85 -25
- package/ios/PCSegmentedControl.swift +231 -308
- package/ios/PCSelectionMenu.swift +60 -14
- package/lib/commonjs/DatePickerNativeComponent.ts +4 -2
- package/lib/commonjs/SegmentedControl.js +138 -6
- package/lib/commonjs/SegmentedControl.js.map +1 -1
- package/lib/commonjs/SegmentedControlNativeComponent.ts +62 -8
- package/lib/commonjs/SelectionMenuNativeComponent.ts +4 -2
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/module/DatePickerNativeComponent.ts +4 -2
- package/lib/module/SegmentedControl.js +138 -7
- package/lib/module/SegmentedControl.js.map +1 -1
- package/lib/module/SegmentedControlNativeComponent.ts +62 -8
- package/lib/module/SelectionMenuNativeComponent.ts +4 -2
- package/lib/module/index.web.js.map +1 -1
- package/lib/typescript/commonjs/src/DatePickerNativeComponent.d.ts +2 -2
- package/lib/typescript/commonjs/src/DatePickerNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/SegmentedControl.d.ts +111 -6
- package/lib/typescript/commonjs/src/SegmentedControl.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/SegmentedControlNativeComponent.d.ts +46 -7
- package/lib/typescript/commonjs/src/SegmentedControlNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/SelectionMenuNativeComponent.d.ts +2 -2
- package/lib/typescript/commonjs/src/SelectionMenuNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.web.d.ts +36 -1
- package/lib/typescript/commonjs/src/index.web.d.ts.map +1 -1
- package/lib/typescript/module/src/DatePicker.d.ts +1 -1
- package/lib/typescript/module/src/DatePicker.d.ts.map +1 -1
- package/lib/typescript/module/src/DatePickerNativeComponent.d.ts +2 -2
- package/lib/typescript/module/src/DatePickerNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/SegmentedControl.d.ts +111 -6
- package/lib/typescript/module/src/SegmentedControl.d.ts.map +1 -1
- package/lib/typescript/module/src/SegmentedControlNativeComponent.d.ts +46 -7
- package/lib/typescript/module/src/SegmentedControlNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/SelectionMenu.d.ts +1 -1
- package/lib/typescript/module/src/SelectionMenu.d.ts.map +1 -1
- package/lib/typescript/module/src/SelectionMenuNativeComponent.d.ts +2 -2
- package/lib/typescript/module/src/SelectionMenuNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +6 -6
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/index.web.d.ts +36 -1
- package/lib/typescript/module/src/index.web.d.ts.map +1 -1
- package/package.json +30 -25
- package/plugin/tsconfig.json +2 -2
- package/src/DatePickerNativeComponent.ts +4 -2
- package/src/SegmentedControl.tsx +238 -11
- package/src/SegmentedControlNativeComponent.ts +62 -8
- package/src/SelectionMenuNativeComponent.ts +4 -2
- package/src/index.web.tsx +34 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#import <React/RCTComponentViewFactory.h>
|
|
6
6
|
#import <React/RCTConversions.h>
|
|
7
7
|
#import <React/RCTFabricComponentsPlugins.h>
|
|
8
|
+
#import <React/RCTFont.h>
|
|
8
9
|
|
|
9
10
|
#import <react/renderer/components/PlatformComponentsViewSpec/ComponentDescriptors.h>
|
|
10
11
|
#import <react/renderer/components/PlatformComponentsViewSpec/EventEmitters.h>
|
|
@@ -32,10 +33,46 @@ static inline bool SegmentsEqual(
|
|
|
32
33
|
if (a[i].label != b[i].label) return false;
|
|
33
34
|
if (a[i].value != b[i].value) return false;
|
|
34
35
|
if (a[i].disabled != b[i].disabled) return false;
|
|
35
|
-
if (a[i].
|
|
36
|
+
if (a[i].iconType != b[i].iconType) return false;
|
|
37
|
+
if (a[i].iconName != b[i].iconName) return false;
|
|
38
|
+
if (a[i].iconUri != b[i].iconUri) return false;
|
|
39
|
+
if (a[i].iconScale != b[i].iconScale) return false;
|
|
40
|
+
if (a[i].iconTinted != b[i].iconTinted) return false;
|
|
41
|
+
if (a[i].badge != b[i].badge) return false;
|
|
42
|
+
if (a[i].accessibilityLabel != b[i].accessibilityLabel) return false;
|
|
36
43
|
}
|
|
37
44
|
return true;
|
|
38
45
|
}
|
|
46
|
+
|
|
47
|
+
static inline NSString *NSStringFromStd(const std::string &s, NSString *fallback) {
|
|
48
|
+
return s.empty() ? fallback : [NSString stringWithUTF8String:s.c_str()];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static inline bool LabelStyleEqual(
|
|
52
|
+
const facebook::react::PCSegmentedControlLabelStyleStruct &a,
|
|
53
|
+
const facebook::react::PCSegmentedControlLabelStyleStruct &b) {
|
|
54
|
+
return a.fontFamily == b.fontFamily && a.fontSize == b.fontSize &&
|
|
55
|
+
a.fontWeight == b.fontWeight && a.fontStyle == b.fontStyle;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Builds the label font from RN-style font props, or nil when every field is
|
|
59
|
+
/// unset so the control keeps the system font.
|
|
60
|
+
static UIFont *FontFromLabelStyle(
|
|
61
|
+
const facebook::react::PCSegmentedControlLabelStyleStruct &style) {
|
|
62
|
+
if (style.fontFamily.empty() && style.fontSize <= 0 &&
|
|
63
|
+
style.fontWeight.empty() && style.fontStyle.empty()) {
|
|
64
|
+
return nil;
|
|
65
|
+
}
|
|
66
|
+
// UISegmentedControl titles default to 13pt; start there so a lone
|
|
67
|
+
// fontWeight or fontStyle doesn't change the size.
|
|
68
|
+
return [RCTFont updateFont:[UIFont systemFontOfSize:13]
|
|
69
|
+
withFamily:NSStringFromStd(style.fontFamily, nil)
|
|
70
|
+
size:style.fontSize > 0 ? @(style.fontSize) : nil
|
|
71
|
+
weight:NSStringFromStd(style.fontWeight, nil)
|
|
72
|
+
style:NSStringFromStd(style.fontStyle, nil)
|
|
73
|
+
variant:nil
|
|
74
|
+
scaleMultiplier:1.0];
|
|
75
|
+
}
|
|
39
76
|
} // namespace
|
|
40
77
|
|
|
41
78
|
@interface PCSegmentedControl ()
|
|
@@ -77,6 +114,12 @@ static inline bool SegmentsEqual(
|
|
|
77
114
|
|
|
78
115
|
eventEmitter->onSelect(payload);
|
|
79
116
|
};
|
|
117
|
+
|
|
118
|
+
_view.onNeedsRemeasure = ^{
|
|
119
|
+
__typeof(self) strongSelf = weakSelf;
|
|
120
|
+
if (!strongSelf) return;
|
|
121
|
+
[strongSelf updateMeasurements];
|
|
122
|
+
};
|
|
80
123
|
}
|
|
81
124
|
return self;
|
|
82
125
|
}
|
|
@@ -88,32 +131,32 @@ static inline bool SegmentsEqual(
|
|
|
88
131
|
const auto prevProps =
|
|
89
132
|
std::static_pointer_cast<const PCSegmentedControlProps>(oldProps);
|
|
90
133
|
|
|
91
|
-
// segments: [{label, value, disabled,
|
|
134
|
+
// segments: [{label, value, disabled, iconType, iconName, iconUri, iconScale,
|
|
135
|
+
// iconTinted, accessibilityLabel}]
|
|
92
136
|
if (!prevProps || !SegmentsEqual(newProps.segments, prevProps->segments)) {
|
|
93
137
|
NSMutableArray *arr = [NSMutableArray new];
|
|
94
138
|
for (const auto &seg : newProps.segments) {
|
|
95
|
-
NSString *label = seg.label.empty()
|
|
96
|
-
? @""
|
|
97
|
-
: [NSString stringWithUTF8String:seg.label.c_str()];
|
|
98
|
-
NSString *value = seg.value.empty()
|
|
99
|
-
? @""
|
|
100
|
-
: [NSString stringWithUTF8String:seg.value.c_str()];
|
|
101
|
-
NSString *disabled = seg.disabled.empty()
|
|
102
|
-
? @"enabled"
|
|
103
|
-
: [NSString stringWithUTF8String:seg.disabled.c_str()];
|
|
104
|
-
NSString *icon = seg.icon.empty()
|
|
105
|
-
? @""
|
|
106
|
-
: [NSString stringWithUTF8String:seg.icon.c_str()];
|
|
107
139
|
[arr addObject:@{
|
|
108
|
-
@"label": label,
|
|
109
|
-
@"value": value,
|
|
110
|
-
@"disabled": disabled,
|
|
111
|
-
@"
|
|
140
|
+
@"label": NSStringFromStd(seg.label, @""),
|
|
141
|
+
@"value": NSStringFromStd(seg.value, @""),
|
|
142
|
+
@"disabled": NSStringFromStd(seg.disabled, @"enabled"),
|
|
143
|
+
@"iconType": NSStringFromStd(seg.iconType, @""),
|
|
144
|
+
@"iconName": NSStringFromStd(seg.iconName, @""),
|
|
145
|
+
@"iconUri": NSStringFromStd(seg.iconUri, @""),
|
|
146
|
+
@"iconScale": @(seg.iconScale),
|
|
147
|
+
@"iconTinted": NSStringFromStd(seg.iconTinted, @"true"),
|
|
148
|
+
@"badge": NSStringFromStd(seg.badge, @""),
|
|
149
|
+
@"accessibilityLabel": NSStringFromStd(seg.accessibilityLabel, @""),
|
|
112
150
|
}];
|
|
113
151
|
}
|
|
114
152
|
_view.segments = arr;
|
|
115
153
|
}
|
|
116
154
|
|
|
155
|
+
// labelVisibility: "auto" | "labeled" | "unlabeled"
|
|
156
|
+
if (!prevProps || newProps.labelVisibility != prevProps->labelVisibility) {
|
|
157
|
+
_view.labelVisibility = NSStringFromStd(newProps.labelVisibility, @"auto");
|
|
158
|
+
}
|
|
159
|
+
|
|
117
160
|
// selectedValue (default "")
|
|
118
161
|
if (!prevProps || newProps.selectedValue != prevProps->selectedValue) {
|
|
119
162
|
if (!newProps.selectedValue.empty()) {
|
|
@@ -147,13 +190,30 @@ static inline bool SegmentsEqual(
|
|
|
147
190
|
_view.apportionsSegmentWidthsByContent = (newIos.apportionsSegmentWidthsByContent == "true");
|
|
148
191
|
}
|
|
149
192
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
193
|
+
// Colors arrive as SharedColor (already processed by React Native)
|
|
194
|
+
if (!prevProps || newProps.selectedSegmentColor != prevProps->selectedSegmentColor) {
|
|
195
|
+
_view.selectedSegmentColor = RCTUIColorFromSharedColor(newProps.selectedSegmentColor);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!prevProps || newProps.activeTintColor != prevProps->activeTintColor) {
|
|
199
|
+
_view.activeTintColor = RCTUIColorFromSharedColor(newProps.activeTintColor);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!prevProps || newProps.inactiveTintColor != prevProps->inactiveTintColor) {
|
|
203
|
+
_view.inactiveTintColor = RCTUIColorFromSharedColor(newProps.inactiveTintColor);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// labelStyle: {fontFamily, fontSize, fontWeight, fontStyle}
|
|
207
|
+
if (!prevProps || !LabelStyleEqual(newProps.labelStyle, prevProps->labelStyle)) {
|
|
208
|
+
_view.labelFont = FontFromLabelStyle(newProps.labelStyle);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!prevProps || newProps.badgeBackgroundColor != prevProps->badgeBackgroundColor) {
|
|
212
|
+
_view.badgeBackgroundColor = RCTUIColorFromSharedColor(newProps.badgeBackgroundColor);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!prevProps || newProps.badgeTextColor != prevProps->badgeTextColor) {
|
|
216
|
+
_view.badgeTextColor = RCTUIColorFromSharedColor(newProps.badgeTextColor);
|
|
157
217
|
}
|
|
158
218
|
|
|
159
219
|
[super updateProps:props oldProps:oldProps];
|