You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ScrollViewstyle={styles.scrollView}><Textstyle={styles.text}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</Text></ScrollView>
const[refreshing,setRefreshing]=useState<boolean>(false);// refreshconstonRefresh=useCallback(async()=>{// do something},[]);<FlatListref={refFlatList}numColumns={2}renderItem={renderItem}keyExtractor={(item)=>item.id}refreshControl={<RefreshControlrefreshing={refreshing}onRefresh={onRefresh}/>}// ...
FlatList 继承了 ScrollView 所以 ScrollView 也一样
列表上拉加载
// more load componentsconstRenderLoadMoreView=()=>{return<Viewstyle={styles.loadMore}><ActivityIndicatorstyle={styles.indicator}size={"small"}animating={true}/><Text>Loading...</Text></View>};constfetchCosplayMore=useCallback(async()=>{// do something},[]);<FlatListref={refFlatList}numColumns={2}renderItem={renderItem}keyExtractor={(item)=>item.id}refreshControl={<RefreshControlrefreshing={refreshing}onRefresh={onRefresh}/>}ListFooterComponent={()=>RenderLoadMoreView()}onEndReached={()=>fetchCosplayMore()}// ...
列表滚动
consthandleScroll=useCallback((e: NativeSyntheticEvent<NativeScrollEvent>)=>{// do something},[]);<FlatListref={refFlatList}numColumns={2}renderItem={renderItem}keyExtractor={(item)=>item.id}refreshControl={<RefreshControlrefreshing={refreshing}onRefresh={onRefresh}/>}ListFooterComponent={()=>RenderLoadMoreView()}onEndReached={()=>fetchCosplayMore()}onScroll={handleScroll}
图片保存 ios
import*asMediaLibraryfrom'expo-media-library';import*asImagePickerfrom'expo-image-picker';consthandleDownload=useCallback(async(url: string): Promise<void>=>{// libraryPermissionResult Object {// "accessPrivileges": "none",// "canAskAgain": false,// "expires": "never",// "granted": false,// "status": "denied",// }// copy doc 不太需要if(Platform.OS!=='web'){const{ status }=awaitImagePicker.getMediaLibraryPermissionsAsync();if(status!=='granted'){// Alert.alert('Sorry, we need media library permissions to make this work!');// return}}else{console.log('no support web')return}// 好像是这个权限 后来不知道怎么清空权限重新获取一下constlibraryPermissionResult=awaitImagePicker.getMediaLibraryPermissionsAsync()console.log('libraryPermissionResult',libraryPermissionResult)// ImagePicker.requestMediaLibraryPermissionsAsync(writeOnly)// Get permissionif(libraryPermissionResult.accessPrivileges==='none'&&libraryPermissionResult.status!=='granted'){awaitImagePicker.requestMediaLibraryPermissionsAsync(true)const_libraryPermissionResult=awaitImagePicker.getMediaLibraryPermissionsAsync()console.log('_libraryPermissionResult',_libraryPermissionResult)if(_libraryPermissionResult.accessPrivileges==='none'&&_libraryPermissionResult.status!=='granted'){return}}// Savetry{// encode 因为图片 url 有中文 会报错awaitMediaLibrary.saveToLibraryAsync(encodeURI(url))Alert.alert('Saved successfully')}catch(error){console.log('error',error)Alert.alert('Save failed')}},[])
import{Share}from'react-native';constonShare=async()=>{try{constresult=awaitShare.share({message:
'React Native | A framework for building native apps using React',});if(result.action===Share.sharedAction){if(result.activityType){// shared with activity type of result.activityType}else{// shared}}elseif(result.action===Share.dismissedAction){// dismissed}}catch(error){alert(error.message);}};
// TODO: type fixconstrefFlatList=useRef<any>(null);// go topconstgoToTop=useCallback(()=>{// 后来看见的 懒得试// https://reactnavigation.org/docs/use-scroll-to-toprefFlatList.current.scrollToOffset({offset: 0});},[refFlatList]);<FlatListref={refFlatList}
import*asReactfrom'react';import{StyleSheet,Text,View}from'react-native';import{LinearGradient}from'expo-linear-gradient';exportdefaultfunctionApp(){return(<Viewstyle={styles.container}><LinearGradient// Background Linear Gradientcolors={['rgba(0,0,0,0.8)','transparent']}style={styles.background}/><LinearGradient// Button Linear Gradientcolors={['#4c669f','#3b5998','#192f6a']}style={styles.button}><Textstyle={styles.text}>Sign in with Facebook</Text></LinearGradient></View>);}conststyles=StyleSheet.create({ ... });
The text was updated successfully, but these errors were encountered:
记录一些觉得有意义的功能点
列表滚动
静态列表 不多的情况我会用 ScrollView
动态加载 包含图片什么的 flatlist
列表下拉刷新
FlatList 继承了 ScrollView 所以 ScrollView 也一样
列表上拉加载
列表滚动
图片保存 ios
ActionSheetIOS
会弹出一个菜单
Share
会出现一个 分享 菜单,和 expo share sdk 有什么区别我还不知道 https://docs.expo.dev/versions/latest/react-native/share/
返回到顶部
reactnavigation 文档也提到了这个功能
react-navigation
https://reactnavigation.org/
navigation.navigate('Detail') 只会产生一条记录
navigation.push('Detail') 会产出N条记录
useFocusEffect
params
navigation.navigate('Detail', params)
...
背景渐变
The text was updated successfully, but these errors were encountered: