Bottom video starts playing when the before last video is focused
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.2k
- Forks
- 393
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 1
Description
Description
We added a screen similar to TikTok where users can scroll vertically between clips. We use Bitmovin player and when the before last video is focused the last video starts playing as well. Same thing when scrolling to the top when the second video is focused the first video starts playing as well.
<FlashList
ref={flashListRef}
data={series?.allSeries}
renderItem={({item, index}) => (
<View
style={{
flex: 1,
height: height,
}}>
<ShortVideoPlayerComponent
item={item}
index={index}
currentIndex={currentIndex}
openRBSheet={openRBSheet}
isActive={index === currentIndex}
/>
</View>
)}
estimatedItemSize={height}
keyExtractor={item => item?._id}
pagingEnabled
snapToInterval={height}
// decelerationRate="fast"
disableIntervalMomentum={true}
onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={{
itemVisiblePercentThreshold: 80, // or 50 for debugging
}}
showsVerticalScrollIndicator={false}
scrollEventThrottle={16}
snapToAlignment="start"
extraData={[currentIndex]}
// style={{flex: 1}}
// contentContainerStyle={{flexGrow: 1}}
// style={{flex: 1}}
/>
const onViewableItemsChanged = useRef(({viewableItems}) => {
if (!viewableItems || viewableItems.length === 0) return;
// Sort by how much of the item is visible (if available)
const sorted = [...viewableItems].sort(
(a, b) => (b?.itemVisiblePercent ?? 0) - (a?.itemVisiblePercent ?? 0),
);
const mostVisibleItem = sorted[0];
if (mostVisibleItem && typeof mostVisibleItem.index === 'number') {
const newIndex = mostVisibleItem.index;
if (newIndex !== currentIndexRef.current) {
currentIndexRef.current = newIndex;
setCurrentIndex(newIndex);
}
}
}).current;
We use the currentIndex and the index to toggle the player:
useEffect(() => {
if (index === currentIndex) {
player?.play();
} else {
player?.pause();
}
}, [currentIndex, index]);
Platform
- iOS
- Android
- Web (if applicable)
Environment
React Native info output:
System:
OS: macOS 15.6.1
CPU: (8) arm64 Apple M1
Memory: 126.64 MB / 8.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 24.6.0
path: /opt/homebrew/bin/node
Yarn:
version: 3.6.4
path: /opt/homebrew/bin/yarn
npm:
version: 10.9.3
path: ~/Desktop/FliikaNew-V2/FliikaMobileRN/node_modules/.bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11255304
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.10
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.73.6
wanted: 0.73.6
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Paste output here
**FlashList version: 1.8.3
Additional context
- I've searched existing issues and couldn't find a duplicate
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied FlashList configuration, onViewableItemsChanged callback, and ShortVideoPlayerComponent effect, then reproduce the boundary scrolling behavior on iOS and Android with React Native 0.73.6 and FlashList 1.8.3. Done means only the currently focused video plays when the second or before-last item is focused, while the adjacent boundary item remains paused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100