Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekDIYHome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huanglu
GeekDIYHome
Commits
9cb714bd
Commit
9cb714bd
authored
Jul 27, 2020
by
huanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: components
parent
63280449
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
26 deletions
+79
-26
index.tsx
src/components/refresh-list-view/index.tsx
+64
-0
index.tsx
src/pages/about/index.tsx
+2
-5
index.tsx
src/pages/home/index.tsx
+13
-21
No files found.
src/components/refresh-list-view/index.tsx
0 → 100644
View file @
9cb714bd
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
src/pages/about/index.tsx
View file @
9cb714bd
...
...
@@ -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
:
2
0
,
backgroundColor
:
'#f0f0f0'
,
overflow
:
'hidden'
}
}
style=
{
{
margin
:
1
0
,
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
>
)
}
...
...
src/pages/home/index.tsx
View file @
9cb714bd
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
(
Refresh
List
State
.
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
(
Refresh
List
State
.
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
(
Refresh
List
State
.
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
>
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment