@javascriptcommon/react-native-carplay 2.3.11 → 2.3.12
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/ios/RNCarPlay.m
CHANGED
|
@@ -113,7 +113,8 @@ RCT_EXPORT_MODULE();
|
|
|
113
113
|
@"selectedPreviewForTrip",
|
|
114
114
|
@"startedTrip",
|
|
115
115
|
@"didSelectRowItem",
|
|
116
|
-
@"templateLoaded"
|
|
116
|
+
@"templateLoaded",
|
|
117
|
+
@"listTemplateLoadMore"
|
|
117
118
|
];
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -258,6 +259,14 @@ RCT_EXPORT_METHOD(createTemplate:(NSString *)templateId config:(NSDictionary*)co
|
|
|
258
259
|
if (config[@"emptyViewSubtitleVariants"]) {
|
|
259
260
|
listTemplate.emptyViewSubtitleVariants = [RCTConvert NSArray:config[@"emptyViewSubtitleVariants"]];
|
|
260
261
|
}
|
|
262
|
+
|
|
263
|
+
// Store infinite scroll configuration in userInfo
|
|
264
|
+
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ @"templateId": templateId }];
|
|
265
|
+
if (config[@"loadMoreThreshold"]) {
|
|
266
|
+
userInfo[@"loadMoreThreshold"] = [RCTConvert NSNumber:config[@"loadMoreThreshold"]];
|
|
267
|
+
}
|
|
268
|
+
[listTemplate setUserInfo:userInfo];
|
|
269
|
+
|
|
261
270
|
listTemplate.delegate = self;
|
|
262
271
|
carPlayTemplate = listTemplate;
|
|
263
272
|
} else {
|
|
@@ -265,6 +274,14 @@ RCT_EXPORT_METHOD(createTemplate:(NSString *)templateId config:(NSDictionary*)co
|
|
|
265
274
|
CPListTemplate *listTemplate = [[CPListTemplate alloc] initWithTitle:title sections:sections];
|
|
266
275
|
[listTemplate setLeadingNavigationBarButtons:leadingNavigationBarButtons];
|
|
267
276
|
[listTemplate setTrailingNavigationBarButtons:trailingNavigationBarButtons];
|
|
277
|
+
|
|
278
|
+
// Store infinite scroll configuration in userInfo
|
|
279
|
+
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ @"templateId": templateId }];
|
|
280
|
+
if (config[@"loadMoreThreshold"]) {
|
|
281
|
+
userInfo[@"loadMoreThreshold"] = [RCTConvert NSNumber:config[@"loadMoreThreshold"]];
|
|
282
|
+
}
|
|
283
|
+
[listTemplate setUserInfo:userInfo];
|
|
284
|
+
|
|
268
285
|
listTemplate.delegate = self;
|
|
269
286
|
carPlayTemplate = listTemplate;
|
|
270
287
|
}
|
|
@@ -1204,15 +1221,17 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
|
|
|
1204
1221
|
- (NSArray<CPListSection*>*)parseSections:(NSArray*)sections templateId:(NSString *)templateId API_AVAILABLE(ios(12.0)) {
|
|
1205
1222
|
NSMutableArray *result = [NSMutableArray array];
|
|
1206
1223
|
int index = 0;
|
|
1224
|
+
int sectionIndex = 0;
|
|
1207
1225
|
for (NSDictionary *section in sections) {
|
|
1208
1226
|
NSArray *items = [section objectForKey:@"items"];
|
|
1209
1227
|
NSString *_sectionIndexTitle = [section objectForKey:@"sectionIndexTitle"];
|
|
1210
1228
|
NSString *_header = [section objectForKey:@"header"];
|
|
1211
|
-
NSArray *_items = [self parseListItems:items startIndex:index templateId:templateId];
|
|
1229
|
+
NSArray *_items = [self parseListItems:items startIndex:index sectionIndex:sectionIndex templateId:templateId];
|
|
1212
1230
|
CPListSection *_section = [[CPListSection alloc] initWithItems:_items header:_header sectionIndexTitle:_sectionIndexTitle];
|
|
1213
1231
|
[result addObject:_section];
|
|
1214
1232
|
int count = (int) [items count];
|
|
1215
1233
|
index = index + count;
|
|
1234
|
+
sectionIndex++;
|
|
1216
1235
|
}
|
|
1217
1236
|
return result;
|
|
1218
1237
|
}
|
|
@@ -1230,7 +1249,7 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
|
|
|
1230
1249
|
}
|
|
1231
1250
|
|
|
1232
1251
|
|
|
1233
|
-
- (NSArray<CPListItem*>*)parseListItems:(NSArray*)items startIndex:(int)startIndex templateId:(NSString *)templateId API_AVAILABLE(ios(12.0)) {
|
|
1252
|
+
- (NSArray<CPListItem*>*)parseListItems:(NSArray*)items startIndex:(int)startIndex sectionIndex:(int)sectionIndex templateId:(NSString *)templateId API_AVAILABLE(ios(12.0)) {
|
|
1234
1253
|
NSMutableArray *_items = [NSMutableArray array];
|
|
1235
1254
|
int index = startIndex;
|
|
1236
1255
|
UIImage *placeholder = [UIImage imageNamed: @"Placeholder"];
|
|
@@ -1297,7 +1316,7 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
|
|
|
1297
1316
|
}
|
|
1298
1317
|
};
|
|
1299
1318
|
|
|
1300
|
-
[_imageRowItem setUserInfo:@{ @"index": @(index) }];
|
|
1319
|
+
[_imageRowItem setUserInfo:@{ @"index": @(index - startIndex), @"sectionIndex": @(sectionIndex) }];
|
|
1301
1320
|
[_items addObject:_imageRowItem];
|
|
1302
1321
|
index = index + 1;
|
|
1303
1322
|
continue;
|
|
@@ -1356,7 +1375,7 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
|
|
|
1356
1375
|
}
|
|
1357
1376
|
}
|
|
1358
1377
|
}
|
|
1359
|
-
[_item setUserInfo:@{ @"index": @(index) }];
|
|
1378
|
+
[_item setUserInfo:@{ @"index": @(index - startIndex), @"sectionIndex": @(sectionIndex) }];
|
|
1360
1379
|
[_items addObject:_item];
|
|
1361
1380
|
index = index + 1;
|
|
1362
1381
|
}
|
|
@@ -1699,6 +1718,34 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
|
|
|
1699
1718
|
NSNumber* index = [item.userInfo objectForKey:@"index"];
|
|
1700
1719
|
[self sendTemplateEventWithName:listTemplate name:@"didSelectListItem" json:@{ @"index": index }];
|
|
1701
1720
|
self.selectedResultBlock = completionHandler;
|
|
1721
|
+
|
|
1722
|
+
// Check for infinite scroll threshold
|
|
1723
|
+
NSNumber* loadMoreThreshold = [listTemplate.userInfo objectForKey:@"loadMoreThreshold"];
|
|
1724
|
+
if (loadMoreThreshold != nil) {
|
|
1725
|
+
// Calculate total items across all sections
|
|
1726
|
+
NSInteger totalItems = 0;
|
|
1727
|
+
for (CPListSection *section in listTemplate.sections) {
|
|
1728
|
+
totalItems += section.items.count;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// Calculate the current absolute index across all sections
|
|
1732
|
+
NSInteger absoluteIndex = [index integerValue];
|
|
1733
|
+
NSInteger sectionIndex = [[item.userInfo objectForKey:@"sectionIndex"] integerValue];
|
|
1734
|
+
for (NSInteger i = 0; i < sectionIndex; i++) {
|
|
1735
|
+
if (i < listTemplate.sections.count) {
|
|
1736
|
+
absoluteIndex += listTemplate.sections[i].items.count;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// Trigger load more if within threshold of the end
|
|
1741
|
+
NSInteger threshold = [loadMoreThreshold integerValue];
|
|
1742
|
+
if (totalItems > 0 && (totalItems - absoluteIndex) <= threshold) {
|
|
1743
|
+
[self sendTemplateEventWithName:listTemplate name:@"listTemplateLoadMore" json:@{
|
|
1744
|
+
@"index": @(absoluteIndex),
|
|
1745
|
+
@"totalItems": @(totalItems)
|
|
1746
|
+
}];
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1702
1749
|
}
|
|
1703
1750
|
}
|
|
1704
1751
|
|
|
@@ -44,6 +44,11 @@ class ListTemplate extends Template_1.Template {
|
|
|
44
44
|
void Promise.resolve(config.onTemplateLoaded());
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
+
CarPlay_1.CarPlay.emitter.addListener('listTemplateLoadMore', e => {
|
|
48
|
+
if (config.onLoadMoreItems && e.templateId === this.id) {
|
|
49
|
+
config.onLoadMoreItems({ index: e.index, totalItems: e.totalItems });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
47
52
|
}
|
|
48
53
|
updateSections = (sections) => {
|
|
49
54
|
return CarPlay_1.CarPlay.bridge.updateListTemplateSections(this.id, this.parseConfig(sections));
|
package/package.json
CHANGED
|
@@ -93,6 +93,21 @@ export interface ListTemplateConfig extends TemplateConfig {
|
|
|
93
93
|
* Set to true if you want to receive the onTemplateLoaded callback
|
|
94
94
|
*/
|
|
95
95
|
needsTemplateLoadedCallback: boolean;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Threshold for triggering the onLoadMoreItems callback.
|
|
99
|
+
* When the user selects an item within this many items from the end,
|
|
100
|
+
* the onLoadMoreItems callback will be triggered.
|
|
101
|
+
* For example, if set to 5, selecting any of the last 5 items will trigger the callback.
|
|
102
|
+
*/
|
|
103
|
+
loadMoreThreshold?: number;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Fired when the user scrolls near the end of the list (based on loadMoreThreshold).
|
|
107
|
+
* This can be used to implement infinite scrolling by loading more items.
|
|
108
|
+
* @param item Object with the current index and total items
|
|
109
|
+
*/
|
|
110
|
+
onLoadMoreItems?(item: { index: number; totalItems: number }): void;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
/**
|
|
@@ -139,6 +154,12 @@ export class ListTemplate extends Template<ListTemplateConfig> {
|
|
|
139
154
|
void Promise.resolve(config.onTemplateLoaded())
|
|
140
155
|
}
|
|
141
156
|
});
|
|
157
|
+
|
|
158
|
+
CarPlay.emitter.addListener('listTemplateLoadMore', e => {
|
|
159
|
+
if (config.onLoadMoreItems && e.templateId === this.id) {
|
|
160
|
+
config.onLoadMoreItems({ index: e.index, totalItems: e.totalItems });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
142
163
|
}
|
|
143
164
|
|
|
144
165
|
public updateSections = (sections: ListSection[]) => {
|