Commit 9cb714bd authored by huanglu's avatar huanglu

fix: components

parent 63280449
import React from 'react'
import RefreshListView, { RefreshState } from 'react-native-refresh-list-view'
import { TouchableHighlight } from 'react-native-gesture-handler'
import { View, Text } from 'react-native'
export enum RefreshListState {
Idle = RefreshState.Idle,
HeaderRefreshing = RefreshState.HeaderRefreshing,
FooterRefreshing = RefreshState.FooterRefreshing,
NoMoreData = RefreshState.NoMoreData,
Failure = RefreshState.Failure
}
export type RrefreshListProps<T> = {
data: T[],
renderItem: (itm: T) => React.ReactNode,
state: RefreshListState,
onHeaderRefresh: (state?: RefreshListState) => void
onFooterRefresh: (state?: RefreshListState) => void
}
const FlastView = (props: RrefreshListProps<any>) => {
const { data, renderItem, state, onHeaderRefresh, onFooterRefresh } = props || {}
const handleRenderItem = (itm: any) => renderItem ? renderItem(itm) : (
<TouchableHighlight underlayColor='#f5f5f5' onPress={() => {
console.log('tap index')
}}>
<View style={{ margin: 10, backgroundColor: 'yellow' }}>
<Text style={{ color: 'red' }}>{JSON.stringify(itm)}</Text>
</View>
</TouchableHighlight>
)
const handleOnHeaderRefresh = () => {
onHeaderRefresh && onHeaderRefresh(state)
}
const handleOnFooterRefresh = () => {
onFooterRefresh && onFooterRefresh(state)
}
return (
<RefreshListView
data={data}
keyExtractor={(index: number) => {
return 'key' + index + 'key'
}}
renderItem={renderItem}
refreshState={state}
onHeaderRefresh={handleOnHeaderRefresh}
onFooterRefresh={handleOnFooterRefresh}
footerRefreshingComponent={
<View style={{ justifyContent: 'center', alignItems: 'center'}}>
<Text style={{ color: 'black' }}>loading...</Text>
</View>
}
/>
)
}
export default FlastView
\ No newline at end of file
......@@ -6,6 +6,7 @@ import { useHeaderShow } from '@/hooks';
import ScrollTabView, { DefaultTabBar, ScrollableTabBar } from 'react-native-scrollable-tab-view'
import RefreshListView, { RefreshState } from 'react-native-refresh-list-view'
import navigate from '@/navigate';
import { Dispatch } from 'global';
type AboutProps = {
dispatch: Dispatch,
......@@ -18,7 +19,6 @@ type AboutProps = {
const Page1 = (props: any) => (<View style={{ flex: 1, backgroundColor: 'blue' }}><Text>Page1</Text></View>)
const Page2 = (props: any) => (<View style={{ flex: 1 }}><Text>Page2</Text></View>)
const Page3 = () => (<View style={{ flex: 1 }}><Text>Page3</Text></View>)
const ListView = (props: any) => {
......@@ -97,15 +97,12 @@ const About = ({ dispatch, ...otherProps }: AboutProps) => {
return (
<ScrollTabView
style={{ margin: 20, backgroundColor: '#f0f0f0', overflow: 'hidden' }}
style={{ margin: 10, backgroundColor: '#f0f0f0', overflow: 'hidden' }}
renderTabBar={() =><ScrollableTabBar />}
tabBarPosition='top'>
<Page1 tabLabel="React" />
<Page2 tabLabel="Flow" />
<ListView tabLabel="Jest" />
<ListView tabLabel="Jest" />
<ListView tabLabel="Jest" />
<ListView tabLabel="Jest" />
</ScrollTabView>
)
}
......
import React, { useEffect, useState } from 'react'
import { View, Text, Button } from "react-native";
import RefreshListView, { RefreshState } from 'react-native-refresh-list-view'
import { useSafeAreaInsets, SafeAreaView } from 'react-native-safe-area-context'
import RefreshListView, { RefreshListState } from '@/components/refresh-list-view'
import { TouchableHighlight } from 'react-native-gesture-handler';
import navigate from '@/navigate';
import { useHeaderShow } from '@/hooks';
......@@ -12,13 +11,13 @@ import { PageProps } from 'global';
// HeaderRefreshing (头部菊花转圈圈中)
// FooterRefreshing (底部菊花转圈圈中)
// NoMoreData (已加载全部数据)
// Failure (加载失败)
// Failure (加载失败
const Home = (props: PageProps) => {
useHeaderShow(true)
const [list, setList] = useState([1,2,3])
const [refreshState, setRefreshState] = useState(RefreshState.Idle)
const [refreshState, setRefreshState] = useState(RefreshListState.Idle)
const navigation = useNavigation()
useEffect(() => {
......@@ -41,23 +40,24 @@ const Home = (props: PageProps) => {
</TouchableHighlight>
)
const onHeaderRefresh = () => {
setRefreshState(RefreshState.HeaderRefreshing)
const onHeaderRefresh = (state: RefreshListState) => {
setRefreshState(RefreshListState.HeaderRefreshing)
console.log('onHeaderRefresh')
setTimeout(() => {
setList([ 1,2,3 ])
setRefreshState(RefreshState.Idle)
setRefreshState(RefreshListState.Idle)
}, 1000);
}
const onFooterRefresh = () => {
setRefreshState(RefreshState.FooterRefreshing)
if (list.length >= 5) {
setRefreshState(RefreshState.NoMoreData)
const onFooterRefresh = (state: RefreshListState) => {
console.log('onHeaderRefresh: ' ,state, RefreshListState.FooterRefreshing)
if (state === RefreshListState.FooterRefreshing) {
return
}
setRefreshState(RefreshListState.FooterRefreshing)
setTimeout(() => {
setList([ ...list, new Date().getTime() ])
setRefreshState(RefreshState.Idle)
setRefreshState(RefreshListState.Idle)
}, 1000);
}
......@@ -65,18 +65,10 @@ const Home = (props: PageProps) => {
<View style={{ flex: 1 }}>
<RefreshListView
data={list}
keyExtractor={(index: number) => {
return 'key' + index + 'key'
}}
renderItem={renderItem}
refreshState={ refreshState }
state={refreshState}
onHeaderRefresh={onHeaderRefresh}
onFooterRefresh={onFooterRefresh}
footerRefreshingComponent={
<View style={{ justifyContent: 'center', alignItems: 'center'}}>
<Text style={{ color: 'black' }}>loading...</Text>
</View>
}
/>
</View>
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment