@shortkitsdk/react-native 0.2.0 → 0.2.2

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.
Files changed (34) hide show
  1. package/android/src/main/java/com/shortkit/reactnative/ShortKitCarouselOverlayBridge.kt +48 -0
  2. package/android/src/main/java/com/shortkit/reactnative/ShortKitFeedView.kt +48 -6
  3. package/android/src/main/java/com/shortkit/reactnative/ShortKitModule.kt +180 -2
  4. package/android/src/main/java/com/shortkit/reactnative/ShortKitOverlayBridge.kt +28 -1
  5. package/android/src/main/java/com/shortkit/reactnative/ShortKitPackage.kt +5 -1
  6. package/android/src/main/java/com/shortkit/reactnative/ShortKitPlayerNativeView.kt +136 -0
  7. package/android/src/main/java/com/shortkit/reactnative/ShortKitPlayerViewManager.kt +35 -0
  8. package/android/src/main/java/com/shortkit/reactnative/ShortKitWidgetNativeView.kt +133 -0
  9. package/android/src/main/java/com/shortkit/reactnative/ShortKitWidgetViewManager.kt +30 -0
  10. package/ios/ShortKitBridge.swift +134 -2
  11. package/ios/ShortKitCarouselOverlayBridge.swift +54 -0
  12. package/ios/ShortKitFeedView.swift +46 -7
  13. package/ios/ShortKitModule.mm +42 -0
  14. package/ios/ShortKitOverlayBridge.swift +23 -1
  15. package/ios/ShortKitPlayerNativeView.swift +186 -0
  16. package/ios/ShortKitPlayerNativeViewManager.mm +28 -0
  17. package/ios/ShortKitWidgetNativeView.swift +168 -0
  18. package/ios/ShortKitWidgetNativeViewManager.mm +27 -0
  19. package/package.json +1 -1
  20. package/src/CarouselOverlayManager.tsx +71 -0
  21. package/src/ShortKitContext.ts +18 -0
  22. package/src/ShortKitFeed.tsx +13 -0
  23. package/src/ShortKitPlayer.tsx +61 -0
  24. package/src/ShortKitProvider.tsx +161 -2
  25. package/src/ShortKitWidget.tsx +63 -0
  26. package/src/index.ts +15 -1
  27. package/src/serialization.ts +16 -2
  28. package/src/specs/NativeShortKitModule.ts +37 -0
  29. package/src/specs/ShortKitPlayerViewNativeComponent.ts +13 -0
  30. package/src/specs/ShortKitWidgetViewNativeComponent.ts +12 -0
  31. package/src/types.ts +82 -3
  32. package/src/useShortKit.ts +5 -1
  33. package/src/useShortKitCarousel.ts +29 -0
  34. package/src/useShortKitPlayer.ts +10 -2
package/src/types.ts CHANGED
@@ -2,12 +2,15 @@ import type { ViewStyle } from 'react-native';
2
2
 
3
3
  // --- Configuration ---
4
4
 
5
+ export type FeedSource = 'algorithmic' | 'custom';
6
+
5
7
  export interface FeedConfig {
6
8
  feedHeight?: FeedHeight;
7
9
  overlay?: OverlayConfig;
8
- carouselMode?: CarouselMode;
10
+ carouselOverlay?: CarouselOverlayConfig;
9
11
  surveyMode?: SurveyMode;
10
12
  muteOnStart?: boolean;
13
+ feedSource?: FeedSource;
11
14
  }
12
15
 
13
16
  export type FeedHeight =
@@ -18,9 +21,9 @@ export type OverlayConfig =
18
21
  | 'none'
19
22
  | { type: 'custom'; component: React.ComponentType };
20
23
 
21
- export type CarouselMode =
24
+ export type CarouselOverlayConfig =
22
25
  | 'none'
23
- | { type: 'template'; name: 'default' };
26
+ | { type: 'custom'; component: React.ComponentType };
24
27
 
25
28
  export type SurveyMode =
26
29
  | 'none'
@@ -30,6 +33,7 @@ export type SurveyMode =
30
33
 
31
34
  export interface ContentItem {
32
35
  id: string;
36
+ playbackId?: string;
33
37
  title: string;
34
38
  description?: string;
35
39
  duration: number;
@@ -42,6 +46,29 @@ export interface ContentItem {
42
46
  commentCount?: number;
43
47
  }
44
48
 
49
+ // --- Custom Feed Types ---
50
+
51
+ export interface CarouselImage {
52
+ url: string;
53
+ alt?: string;
54
+ }
55
+
56
+ export interface ImageCarouselItem {
57
+ id: string;
58
+ images: CarouselImage[];
59
+ autoScrollInterval?: number;
60
+ caption?: string;
61
+ title?: string;
62
+ description?: string;
63
+ author?: string;
64
+ section?: string;
65
+ articleUrl?: string;
66
+ }
67
+
68
+ export type CustomFeedItem =
69
+ | { type: 'video'; playbackId: string }
70
+ | { type: 'imageCarousel'; item: ImageCarouselItem };
71
+
45
72
  export type JSONValue =
46
73
  | string
47
74
  | number
@@ -109,6 +136,7 @@ export interface ShortKitError {
109
136
  export interface ShortKitProviderProps {
110
137
  apiKey: string;
111
138
  config: FeedConfig;
139
+ embedId?: string;
112
140
  userId?: string;
113
141
 
114
142
  clientAppName?: string;
@@ -127,6 +155,55 @@ export interface ShortKitFeedProps {
127
155
  onLoop?: (event: LoopEvent) => void;
128
156
  onFeedTransition?: (event: FeedTransitionEvent) => void;
129
157
  onFormatChange?: (event: FormatChangeEvent) => void;
158
+ onContentTapped?: (contentId: string, index: number) => void;
159
+ }
160
+
161
+ // --- Single Player Config ---
162
+
163
+ export type PlayerClickAction = 'feed' | 'mute' | 'none';
164
+
165
+ export interface PlayerConfig {
166
+ cornerRadius?: number;
167
+ clickAction?: PlayerClickAction;
168
+ autoplay?: boolean;
169
+ loop?: boolean;
170
+ muteOnStart?: boolean;
171
+ overlay?: OverlayConfig;
172
+ }
173
+
174
+ // --- Widget Config ---
175
+
176
+ export interface WidgetConfig {
177
+ cardCount?: number;
178
+ cardSpacing?: number;
179
+ cornerRadius?: number;
180
+ autoplay?: boolean;
181
+ muteOnStart?: boolean;
182
+ loop?: boolean;
183
+ rotationInterval?: number;
184
+ clickAction?: PlayerClickAction;
185
+ overlay?: OverlayConfig;
186
+ }
187
+
188
+ // --- Single Player Props ---
189
+
190
+ export interface ShortKitPlayerProps {
191
+ config?: PlayerConfig;
192
+ contentItem?: ContentItem;
193
+ /** Controls whether the player is actively playing. When `false` the player
194
+ * returns to thumbnail-only mode without tearing down the view. Defaults to
195
+ * the value of `config.autoplay` (which itself defaults to `true`). */
196
+ active?: boolean;
197
+ style?: ViewStyle;
198
+ onTap?: () => void;
199
+ }
200
+
201
+ // --- Widget Props ---
202
+
203
+ export interface ShortKitWidgetProps {
204
+ config?: WidgetConfig;
205
+ items?: ContentItem[];
206
+ style?: ViewStyle;
130
207
  }
131
208
 
132
209
  // --- Hook Return Types ---
@@ -135,6 +212,7 @@ export interface ShortKitPlayerState {
135
212
  playerState: PlayerState;
136
213
  currentItem: ContentItem | null;
137
214
  nextItem: ContentItem | null;
215
+ activeCellType: 'video' | 'carousel' | null;
138
216
  time: PlayerTime;
139
217
  isMuted: boolean;
140
218
  playbackRate: number;
@@ -142,6 +220,7 @@ export interface ShortKitPlayerState {
142
220
  activeCaptionTrack: CaptionTrack | null;
143
221
  activeCue: { text: string; startTime: number; endTime: number } | null;
144
222
  prefetchedAheadCount: number;
223
+ remainingContentCount: number;
145
224
  isActive: boolean;
146
225
  isTransitioning: boolean;
147
226
  lastOverlayTap: number;
@@ -6,7 +6,7 @@ import { ShortKitContext } from './ShortKitContext';
6
6
  *
7
7
  * Must be used within a `<ShortKitProvider>`.
8
8
  *
9
- * @returns SDK operations: `setUserId` and `clearUserId`.
9
+ * @returns SDK operations and state.
10
10
  */
11
11
  export function useShortKit() {
12
12
  const context = useContext(ShortKitContext);
@@ -16,5 +16,9 @@ export function useShortKit() {
16
16
  return {
17
17
  setUserId: context.setUserId,
18
18
  clearUserId: context.clearUserId,
19
+ setFeedItems: context.setFeedItems,
20
+ appendFeedItems: context.appendFeedItems,
21
+ fetchContent: context.fetchContent,
22
+ remainingContentCount: context.remainingContentCount,
19
23
  };
20
24
  }
@@ -0,0 +1,29 @@
1
+ import { useContext } from 'react';
2
+ import { ShortKitContext } from './ShortKitContext';
3
+ import type { ImageCarouselItem } from './types';
4
+
5
+ export interface ShortKitCarouselState {
6
+ currentCarouselItem: ImageCarouselItem | null;
7
+ isCarouselActive: boolean;
8
+ isCarouselTransitioning: boolean;
9
+ }
10
+
11
+ /**
12
+ * Hook to access carousel overlay state from the nearest ShortKitProvider.
13
+ *
14
+ * Use this inside a custom carousel overlay component to get the current
15
+ * `ImageCarouselItem` data (images, title, description, etc.).
16
+ *
17
+ * Must be used within a `<ShortKitProvider>`.
18
+ */
19
+ export function useShortKitCarousel(): ShortKitCarouselState {
20
+ const context = useContext(ShortKitContext);
21
+ if (!context) {
22
+ throw new Error('useShortKitCarousel must be used within a ShortKitProvider');
23
+ }
24
+ return {
25
+ currentCarouselItem: context.currentCarouselItem,
26
+ isCarouselActive: context.isCarouselActive,
27
+ isCarouselTransitioning: context.isCarouselTransitioning,
28
+ };
29
+ }
@@ -16,12 +16,20 @@ export function useShortKitPlayer(): ShortKitPlayerState {
16
16
  throw new Error('useShortKitPlayer must be used within a ShortKitProvider');
17
17
  }
18
18
 
19
- // Return only player-related state and commands (exclude SDK operations
20
- // and internal fields)
19
+ // Return only player-related state and commands (exclude SDK operations,
20
+ // carousel state, and internal fields)
21
21
  const {
22
22
  setUserId: _setUserId,
23
23
  clearUserId: _clearUserId,
24
+ setFeedItems: _setFeedItems,
25
+ appendFeedItems: _appendFeedItems,
26
+ fetchContent: _fetchContent,
27
+ currentCarouselItem: _currentCarouselItem,
28
+ nextCarouselItem: _nextCarouselItem,
29
+ isCarouselActive: _isCarouselActive,
30
+ isCarouselTransitioning: _isCarouselTransitioning,
24
31
  _overlayConfig: _overlay,
32
+ _carouselOverlayConfig: _carouselOverlay,
25
33
  ...playerState
26
34
  } = context;
27
35