@javascriptcommon/react-native-carplay 2.4.5 → 2.4.7

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
@@ -84,6 +84,7 @@ RCT_EXPORT_MODULE();
84
84
  // list
85
85
  @"didSelectListItem",
86
86
  @"didSelectListItemRowImage",
87
+ @"scrollToBottom",
87
88
  // search
88
89
  @"updatedSearchText",
89
90
  @"searchButtonPressed",
@@ -457,7 +458,14 @@ RCT_EXPORT_METHOD(createTemplate:(NSString *)templateId config:(NSDictionary*)co
457
458
  carPlayTemplate.tabTitle = [RCTConvert NSString:config[@"tabTitle"]];
458
459
  }
459
460
 
460
- [carPlayTemplate setUserInfo:@{ @"templateId": templateId }];
461
+ // Set userInfo with templateId and optional scrollBottomThreshold for list templates
462
+ NSMutableDictionary *userInfo = [@{ @"templateId": templateId } mutableCopy];
463
+ if ([type isEqualToString:@"list"] && config[@"scrollBottomThreshold"]) {
464
+ userInfo[@"scrollBottomThreshold"] = [RCTConvert NSNumber:config[@"scrollBottomThreshold"]];
465
+ } else if ([type isEqualToString:@"list"]) {
466
+ userInfo[@"scrollBottomThreshold"] = @(5); // default threshold
467
+ }
468
+ [carPlayTemplate setUserInfo:userInfo];
461
469
  [store setTemplate:templateId template:carPlayTemplate];
462
470
  }
463
471
 
@@ -1522,6 +1530,35 @@ RCT_EXPORT_METHOD(updateMapTemplateMapButtons:(NSString*) templateId mapButtons:
1522
1530
  NSNumber* index = [item.userInfo objectForKey:@"index"];
1523
1531
  [self sendTemplateEventWithName:listTemplate name:@"didSelectListItem" json:@{ @"index": index }];
1524
1532
  self.selectedResultBlock = completionHandler;
1533
+
1534
+ // Check if we should trigger scroll to bottom callback for infinite scroll
1535
+ NSDictionary *templateUserInfo = [listTemplate userInfo];
1536
+ NSNumber *scrollBottomThreshold = [templateUserInfo objectForKey:@"scrollBottomThreshold"];
1537
+
1538
+ if (scrollBottomThreshold) {
1539
+ // Calculate total number of items across all sections
1540
+ NSInteger totalItems = 0;
1541
+ for (CPListSection *section in listTemplate.sections) {
1542
+ totalItems += section.items.count;
1543
+ }
1544
+
1545
+ // Get the current index
1546
+ NSInteger currentIndex = [index integerValue];
1547
+
1548
+ // Calculate remaining items
1549
+ NSInteger remainingItems = totalItems - currentIndex - 1;
1550
+
1551
+ // If we're within the threshold from the end, fire the event
1552
+ if (remainingItems <= [scrollBottomThreshold integerValue]) {
1553
+ NSString *templateId = [templateUserInfo objectForKey:@"templateId"];
1554
+ if (self->hasListeners && templateId) {
1555
+ [self sendEventWithName:@"scrollToBottom" body:@{
1556
+ @"templateId": templateId,
1557
+ @"remainingItems": @(remainingItems)
1558
+ }];
1559
+ }
1560
+ }
1561
+ }
1525
1562
  }
1526
1563
 
1527
1564
  # pragma TabBarTemplate
@@ -66,6 +66,22 @@ export interface ListTemplateConfig extends TemplateConfig {
66
66
  * Fired when the back button is pressed
67
67
  */
68
68
  onBackButtonPressed?(): void;
69
+ /**
70
+ * Fired when user scrolls close to the bottom of the list.
71
+ * Useful for implementing infinite scroll / pagination.
72
+ * @param e Object with remainingItems count
73
+ * @namespace iOS
74
+ */
75
+ onScrollToBottom?(e: {
76
+ templateId: string;
77
+ remainingItems: number;
78
+ }): void;
79
+ /**
80
+ * Number of items from the bottom that triggers onScrollToBottom callback.
81
+ * @default 5
82
+ * @namespace iOS
83
+ */
84
+ scrollBottomThreshold?: number;
69
85
  /**
70
86
  * Option to hide back button
71
87
  * @default false
@@ -1 +1 @@
1
- {"version":3,"file":"ListTemplate.d.ts","sourceRoot":"","sources":["../../src/templates/ListTemplate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC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MAIX;gBAEkB,MAAM,EAAE,kBAAkB;IAoCtC,cAAc,aAAc,WAAW,EAAE,UAG9C;IAEK,sBAAsB,WAAY,cAAc,UAMrD;IAEK,uBAAuB;IAIvB,0BAA0B;IAI1B,2BAA2B;IAI3B,4BAA4B;IAI5B,mCAAmC;CAG3C"}
@@ -44,6 +44,11 @@ class ListTemplate extends Template_1.Template {
44
44
  });
45
45
  }
46
46
  });
47
+ CarPlay_1.CarPlay.emitter.addListener('scrollToBottom', (e) => {
48
+ if (config.onScrollToBottom && e.templateId === this.id) {
49
+ config.onScrollToBottom(e);
50
+ }
51
+ });
47
52
  }
48
53
  updateSections = (sections) => {
49
54
  this.config.sections = sections;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@javascriptcommon/react-native-carplay",
3
- "version": "2.4.5",
3
+ "version": "2.4.7",
4
4
  "description": "CarPlay for React Native",
5
5
  "main": "lib/index.js",
6
6
  "react-native": "src/index.ts",
@@ -69,6 +69,21 @@ export interface ListTemplateConfig extends TemplateConfig {
69
69
  */
70
70
  onBackButtonPressed?(): void;
71
71
 
72
+ /**
73
+ * Fired when user scrolls close to the bottom of the list.
74
+ * Useful for implementing infinite scroll / pagination.
75
+ * @param e Object with remainingItems count
76
+ * @namespace iOS
77
+ */
78
+ onScrollToBottom?(e: { templateId: string; remainingItems: number }): void;
79
+
80
+ /**
81
+ * Number of items from the bottom that triggers onScrollToBottom callback.
82
+ * @default 5
83
+ * @namespace iOS
84
+ */
85
+ scrollBottomThreshold?: number;
86
+
72
87
  /**
73
88
  * Option to hide back button
74
89
  * @default false
@@ -150,6 +165,15 @@ export class ListTemplate extends Template<ListTemplateConfig> {
150
165
  }
151
166
  },
152
167
  );
168
+
169
+ CarPlay.emitter.addListener(
170
+ 'scrollToBottom',
171
+ (e: { templateId: string; remainingItems: number }) => {
172
+ if (config.onScrollToBottom && e.templateId === this.id) {
173
+ config.onScrollToBottom(e);
174
+ }
175
+ },
176
+ );
153
177
  }
154
178
 
155
179
  public updateSections = (sections: ListSection[]) => {