@@ -313,7 +313,6 @@ The following example implements a horizontal scrolling carousel where the scrol
313313```SnackPlayer name=Animated&supportedPlatforms=ios,android
314314import React, {useRef} from 'react';
315315import {
316- SafeAreaView,
317316 ScrollView,
318317 Text,
319318 StyleSheet,
@@ -322,6 +321,7 @@ import {
322321 Animated,
323322 useWindowDimensions,
324323} from 'react-native';
324+ import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
325325
326326const images = new Array(6).fill(
327327 'https:// images.unsplash.com/photo-1556740749-887f6717d7e4',
@@ -333,57 +333,61 @@ const App = () => {
333333 const {width : windowWidth} = useWindowDimensions ();
334334
335335 return (
336- <SafeAreaView style = { styles .container } >
337- <View style = { styles .scrollContainer } >
338- <ScrollView
339- horizontal = { true }
340- pagingEnabled
341- showsHorizontalScrollIndicator = { false }
342- onScroll = { Animated .event ([
343- {
344- nativeEvent: {
345- contentOffset: {
346- x: scrollX ,
336+ <SafeAreaProvider >
337+ <SafeAreaView style = { styles .container } >
338+ <View style = { styles .scrollContainer } >
339+ <ScrollView
340+ horizontal = { true }
341+ pagingEnabled
342+ showsHorizontalScrollIndicator = { false }
343+ onScroll = { Animated .event ([
344+ {
345+ nativeEvent: {
346+ contentOffset: {
347+ x: scrollX ,
348+ },
347349 },
348350 },
349- },
350- ])}
351- scrollEventThrottle = { 1 } >
352- { images .map ((image , imageIndex ) => {
353- return (
354- <View style = { {width: windowWidth , height: 250 }} key = { imageIndex } >
355- <ImageBackground source = { {uri: image }} style = { styles .card } >
356- <View style = { styles .textContainer } >
357- <Text style = { styles .infoText } >
358- { ' Image - ' + imageIndex }
359- </Text >
360- </View >
361- </ImageBackground >
362- </View >
363- );
364- })}
365- </ScrollView >
366- <View style = { styles .indicatorContainer } >
367- { images .map ((image , imageIndex ) => {
368- const width = scrollX .interpolate ({
369- inputRange: [
370- windowWidth * (imageIndex - 1 ),
371- windowWidth * imageIndex ,
372- windowWidth * (imageIndex + 1 ),
373- ],
374- outputRange: [8 , 16 , 8 ],
375- extrapolate: ' clamp' ,
376- });
377- return (
378- <Animated.View
379- key = { imageIndex }
380- style = { [styles .normalDot , {width }]}
381- />
382- );
383- })}
351+ ])}
352+ scrollEventThrottle = { 1 } >
353+ { images .map ((image , imageIndex ) => {
354+ return (
355+ <View
356+ style = { {width: windowWidth , height: 250 }}
357+ key = { imageIndex } >
358+ <ImageBackground source = { {uri: image }} style = { styles .card } >
359+ <View style = { styles .textContainer } >
360+ <Text style = { styles .infoText } >
361+ { ' Image - ' + imageIndex }
362+ </Text >
363+ </View >
364+ </ImageBackground >
365+ </View >
366+ );
367+ })}
368+ </ScrollView >
369+ <View style = { styles .indicatorContainer } >
370+ { images .map ((image , imageIndex ) => {
371+ const width = scrollX .interpolate ({
372+ inputRange: [
373+ windowWidth * (imageIndex - 1 ),
374+ windowWidth * imageIndex ,
375+ windowWidth * (imageIndex + 1 ),
376+ ],
377+ outputRange: [8 , 16 , 8 ],
378+ extrapolate: ' clamp' ,
379+ });
380+ return (
381+ <Animated.View
382+ key = { imageIndex }
383+ style = { [styles .normalDot , {width }]}
384+ />
385+ );
386+ })}
387+ </View >
384388 </View >
385- </View >
386- </SafeAreaView >
389+ </SafeAreaView >
390+ </SafeAreaProvider >
387391 );
388392};
389393
0 commit comments