Code mẫu sử dụng scrollview trong react native

d52bb1 2024

Code mẫu

 

import { RefreshControl, SafeAreaView, ScrollView, StyleSheet, Text, View } from 'react-native'
import React, { useCallback, useState } from 'react'


const App = () => {
 const [reloading, setReloading] = useState(false)
 // const startReload = useCallback ( ()=>{  }, []);
 const startReload = useCallback ( ()=>{
   setReloading(true);   
   console.log("Bắt đầu Reload");
   setTimeout(() => {
     setReloading(false);
     console.log("Kết thúc reload");
    
   }, 3000);
  
  }, []);
 return (
   <View    style={{ height: 200, backgroundColor: 'cyan'}}>
     <Text>App</Text>


     <SafeAreaView>
       <ScrollView
         horizontal={false}
         refreshControl={ 
             <RefreshControl refreshing={reloading} onRefresh={startReload} />
         }
       >
           <Text  style={{fontSize: 40}}>
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
             Nội dung muốn trình bày mà không gian còn thiếu......
           </Text>
       </ScrollView>
     </SafeAreaView>
   </View>
 )
}


export default App
Nguồn: zezo.dev