@shortkitsdk/react-native
v0.2.68
Published
ShortKit React Native SDK — short-form video feed
Downloads
2,152
Readme
ShortKit React Native SDK — Carousel Navigation API
Android support coming in the next release. The carousel navigation API is currently iOS-only. Android stubs are present but return defaults.
Video Carousel Navigation
Navigate videos within a carousel item using the useShortKitCarousel() hook or imperative commands.
Hook-based Navigation
Access carousel state and imperative controls using useShortKitCarousel():
import { useShortKitCarousel } from '@shortkitsdk/react-native';
import { View, Text, Button } from 'react-native';
function MyCarouselControls() {
const { activeIndex, videoCount, next, previous, setActiveIndex } = useShortKitCarousel();
if (activeIndex === null) {
return null; // no carousel currently active
}
return (
<View style={{ padding: 16 }}>
<Text style={{ marginBottom: 12 }}>
{activeIndex + 1} of {videoCount}
</Text>
<View style={{ flexDirection: 'row', gap: 8 }}>
<Button
title="Previous"
onPress={previous}
disabled={activeIndex === 0}
/>
<Button
title="Next"
onPress={next}
disabled={activeIndex === videoCount - 1}
/>
</View>
</View>
);
}The hook returns:
activeIndex: Current video index in the carousel, ornullif no carousel is activevideoCount: Total number of videos in the active carouselactiveCarouselItem: The full carousel item object, ornullif nonenext(): Advance to the next video (returnsfalseat the last index)previous(): Go to the previous video (returnsfalseat index 0)setActiveIndex(index): Jump to a specific index (returnsfalseif out of range)
Imperative Commands (Inside Overlay Surfaces)
For overlay components that run in isolated React surfaces and cannot access context, use ShortKitCommands directly:
import { ShortKitCommands } from '@shortkitsdk/react-native';
import { Pressable, Text } from 'react-native';
function CarouselOverlay() {
return (
<Pressable
onPress={() => {
const success = ShortKitCommands.carouselNext();
if (!success) {
// already at the last video
}
}}
>
<Text>Next Video</Text>
</Pressable>
);
}Available carousel commands:
carouselNext(): Advance to the next video (returnsfalseif already at last index)carouselPrevious(): Go to the previous video (returnsfalseif already at index 0)carouselSetActiveIndex(index): Jump to a specific index (returnsfalseif out of range)
Completion Event Handling
Use the onCarouselActiveVideoCompleted callback on <ShortKitFeed> to react when a video completes playback:
<ShortKitFeed
onCarouselActiveVideoCompleted={(event) => {
console.log(`Video ${event.indexInCarousel} completed in carousel`);
if (event.wasLast && !event.willAutoAdvance) {
// Show an "End of carousel" call-to-action
showEndOfCarouselCTA({
contentItem: event.contentItem,
carouselItem: event.carouselItem,
});
}
}}
/>Event properties:
surfaceId: Identifier of the overlay surfacecontentItem: The video that just completedindexInCarousel: Index of the completed video within the carouselcarouselItem: The full carousel itemwasLast: Whether this was the last video in the carouselwillAutoAdvance: Whether the carousel will automatically advance (alwaysfalsefor the last video)
Behavior Contract
- Boundary returns:
next()returnsfalsewhen already at the last index;previous()returnsfalseat index 0;setActiveIndex()returnsfalsefor out-of-range indices. - Last video loops: The final video loops automatically; it does not advance to the next feed item.
- Completion event only on natural end:
onCarouselActiveVideoCompletedfires when a video reaches the end naturally. It does not fire for user-initiated swipes or programmatic navigation. - Auto-advance: When a non-final video completes, the SDK automatically advances to the next video (same as a user swipe). This behavior is suppressed if the user is mid-drag on the carousel.
Example: End-of-Carousel CTA
Build a custom call-to-action when the carousel reaches its end:
function FeedWithCarouselCTA() {
const [showCTA, setShowCTA] = useState(false);
return (
<>
<ShortKitFeed
onCarouselActiveVideoCompleted={(event) => {
if (event.wasLast) {
setShowCTA(true);
}
}}
/>
{showCTA && (
<View style={{ padding: 20, backgroundColor: 'rgba(0,0,0,0.8)' }}>
<Text style={{ color: 'white', fontSize: 16, marginBottom: 12 }}>
You've seen all videos in this collection!
</Text>
<Button
title="Explore More"
onPress={() => {
setShowCTA(false);
}}
/>
</View>
)}
</>
);
}