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
bab4259c
Commit
bab4259c
authored
Jul 27, 2020
by
huanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update components
parent
9cb714bd
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
134 additions
and
59 deletions
+134
-59
index.ts
src/components/index.ts
+8
-0
index.tsx
src/components/refresh-list-view/index.tsx
+4
-2
CustomTabBar.tsx
src/components/tab-list-view/CustomTabBar.tsx
+25
-0
index.tsx
src/components/tab-list-view/index.tsx
+43
-0
index.tsx
src/pages/about/index.tsx
+39
-50
index.tsx
src/pages/home/index.tsx
+9
-7
index.ts
src/utils/index.ts
+6
-0
No files found.
src/components/index.ts
0 → 100644
View file @
bab4259c
import
RefreshListView
from
'./refresh-list-view'
import
{
TabListView
,
TabListItem
}
from
'./tab-list-view'
export
{
RefreshListView
,
TabListView
,
TabListItem
}
\ No newline at end of file
src/components/refresh-list-view/index.tsx
View file @
bab4259c
...
@@ -40,14 +40,13 @@ const FlastView = (props: RrefreshListProps<any>) => {
...
@@ -40,14 +40,13 @@ const FlastView = (props: RrefreshListProps<any>) => {
const
handleOnFooterRefresh
=
()
=>
{
const
handleOnFooterRefresh
=
()
=>
{
onFooterRefresh
&&
onFooterRefresh
(
state
)
onFooterRefresh
&&
onFooterRefresh
(
state
)
}
}
return
(
return
(
<
RefreshListView
<
RefreshListView
data=
{
data
}
data=
{
data
}
keyExtractor=
{
(
index
:
number
)
=>
{
keyExtractor=
{
(
index
:
number
)
=>
{
return
'key'
+
index
+
'key'
return
'key'
+
index
+
'key'
}
}
}
}
renderItem=
{
r
enderItem
}
renderItem=
{
handleR
enderItem
}
refreshState=
{
state
}
refreshState=
{
state
}
onHeaderRefresh=
{
handleOnHeaderRefresh
}
onHeaderRefresh=
{
handleOnHeaderRefresh
}
onFooterRefresh=
{
handleOnFooterRefresh
}
onFooterRefresh=
{
handleOnFooterRefresh
}
...
@@ -60,4 +59,6 @@ const FlastView = (props: RrefreshListProps<any>) => {
...
@@ -60,4 +59,6 @@ const FlastView = (props: RrefreshListProps<any>) => {
)
)
}
}
FlastView
.
RefreshListState
=
RefreshListState
export
default
FlastView
export
default
FlastView
\ No newline at end of file
src/components/tab-list-view/CustomTabBar.tsx
0 → 100644
View file @
bab4259c
import
{
View
,
StyleSheet
,
Text
}
from
"react-native"
import
{
rpx
}
from
"@/utils"
import
React
from
"react"
import
{
ScrollableTabBar
,
DefaultTabBar
}
from
"react-native-scrollable-tab-view"
export
default
(
props
:
{
goToPage
?:
(
pageNumber
:
number
)
=>
void
;
tabs
?:
JSX
.
Element
[];
activeTab
?:
number
;
containerWidth
?:
number
;
})
=>
{
console
.
log
(
props
)
return
(
<
View
style=
{
styles
.
tabBarWrap
}
>
<
DefaultTabBar
{
...
props
}
tabStyle=
{
{
borderBottomWidth
:
0
}
}
style=
{
{
borderBottomWidth
:
0
}
}
/>
</
View
>
)
}
const
styles
=
StyleSheet
.
create
({
tabBarWrap
:
{
height
:
rpx
(
44
)
}
})
\ No newline at end of file
src/components/tab-list-view/index.tsx
0 → 100644
View file @
bab4259c
import
React
,
{
useEffect
,
useState
}
from
'react'
import
{
View
,
Text
,
TouchableHighlight
}
from
"react-native"
;
import
ScrollTabView
,
{
DefaultTabBar
,
ScrollableTabBar
}
from
'react-native-scrollable-tab-view'
import
CustomTabBar
from
'./CustomTabBar'
;
type
TabListViewChilrenProps
=
{
tabLabel
:
string
,
children
:
JSX
.
Element
}
type
TabListViewProps
=
{
children
:
JSX
.
Element
,
style
:
React
.
CSSProperties
}
const
TabListItem
=
(
props
:
TabListViewChilrenProps
)
=>
{
return
<>
{
props
.
children
}
</>
}
const
TabListView
=
(
props
:
TabListViewProps
)
=>
{
return
(
<
ScrollTabView
style=
{
{
backgroundColor
:
'#fff'
,
overflow
:
'hidden'
}
}
renderTabBar=
{
()
=>
<
CustomTabBar
/>
}
tabBarPosition=
'top'
>
{
React
.
Children
.
map
(
props
.
children
,
(
child
)
=>
{
if
(
child
.
type
&&
child
.
type
.
name
===
'TabListItem'
)
{
return
child
}
return
null
})
}
</
ScrollTabView
>
)
}
export
{
TabListView
,
TabListItem
}
\ No newline at end of file
src/pages/about/index.tsx
View file @
bab4259c
import
React
,
{
useEffect
,
useState
}
from
'react'
import
React
,
{
useEffect
,
useState
}
from
'react'
import
{
View
,
Text
,
TouchableHighlight
}
from
"react-native"
;
import
{
View
,
Text
,
TouchableHighlight
}
from
"react-native"
;
import
{
useNavigation
,
NavigationProp
}
from
'@react-navigation/native'
;
import
{
connect
}
from
'react-redux'
;
import
{
connect
}
from
'react-redux'
;
import
{
useHeaderShow
}
from
'@/hooks'
;
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
navigate
from
'@/navigate'
;
import
{
Dispatch
}
from
'global'
;
import
{
Dispatch
}
from
'global'
;
import
{
TabListView
,
TabListItem
,
RefreshListView
}
from
'@/components'
;
import
{
SafeAreaView
,
useSafeAreaInsets
,
useSafeArea
}
from
'react-native-safe-area-context'
;
import
{
useNavigation
}
from
'@react-navigation/native'
;
const
{
RefreshListState
}
=
RefreshListView
type
AboutProps
=
{
type
AboutProps
=
{
dispatch
:
Dispatch
,
dispatch
:
Dispatch
,
...
@@ -18,65 +20,61 @@ type AboutProps = {
...
@@ -18,65 +20,61 @@ type AboutProps = {
}
}
const
Page1
=
(
props
:
any
)
=>
(<
View
style=
{
{
flex
:
1
,
backgroundColor
:
'blue'
}
}
><
Text
>
Page1
</
Text
></
View
>)
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
ListView
=
(
props
:
any
)
=>
{
const
ListView
=
(
props
:
any
)
=>
{
const
[
list
,
setList
]
=
useState
([
1
,
2
,
3
])
const
[
list
,
setList
]
=
useState
([
1
,
2
,
3
])
const
[
refreshState
,
setRefreshState
]
=
useState
(
RefreshState
.
Idle
)
const
[
refreshState
,
setRefreshState
]
=
useState
(
RefreshListState
.
Idle
)
const
navigation
=
useNavigation
()
useEffect
(()
=>
{
useEffect
(()
=>
{
console
.
log
(
props
)
const
handleFocus
=
()
=>
{
props
.
navigation
}
navigation
.
addListener
(
'focus'
,
handleFocus
)
return
()
=>
{
navigation
.
removeListener
(
'focus'
,
handleFocus
)
}
},
[])
},
[])
const
renderItem
=
(
itm
:
any
)
=>
(
const
renderItem
=
(
itm
:
any
)
=>
(
<
TouchableHighlight
underlayColor=
'#f5f5f5'
onPress=
{
()
=>
{
<
TouchableHighlight
underlayColor=
'#f5f5f5'
onPress=
{
()
=>
{
navigate
.
navigateAbout
()
navigate
.
navigateAbout
()
}
}
>
}
}
>
<
View
style=
{
{
margin
Bottom
:
15
,
backgroundColor
:
'yellow'
}
}
>
<
View
style=
{
{
margin
:
10
,
backgroundColor
:
'yellow'
}
}
>
<
Text
style=
{
{
color
:
'red'
}
}
>
{
JSON
.
stringify
(
itm
)
}
</
Text
>
<
Text
style=
{
{
color
:
'red'
}
}
>
{
JSON
.
stringify
(
itm
)
}
</
Text
>
</
View
>
</
View
>
</
TouchableHighlight
>
</
TouchableHighlight
>
)
)
const
onHeaderRefresh
=
()
=>
{
const
onHeaderRefresh
=
(
state
)
=>
{
setRefreshState
(
RefreshState
.
HeaderRefreshing
)
setRefreshState
(
RefreshListState
.
HeaderRefreshing
)
console
.
log
(
'onHeaderRefresh'
)
setTimeout
(()
=>
{
setTimeout
(()
=>
{
setList
([
1
,
2
,
3
])
setList
([
1
,
2
,
3
])
setRefreshState
(
RefreshState
.
Idle
)
setRefreshState
(
Refresh
List
State
.
Idle
)
},
1000
);
},
1000
);
}
}
const
onFooterRefresh
=
()
=>
{
const
onFooterRefresh
=
(
state
)
=>
{
console
.
log
(
'onFooterRefresh'
)
if
(
state
===
RefreshListState
.
FooterRefreshing
||
list
.
length
>
10
)
{
setRefreshState
(
RefreshState
.
FooterRefreshing
)
setRefreshState
(
RefreshListState
.
NoMoreData
)
if
(
list
.
length
>=
5
)
{
setRefreshState
(
RefreshState
.
NoMoreData
)
return
return
}
}
setRefreshState
(
RefreshListState
.
FooterRefreshing
)
setTimeout
(()
=>
{
setTimeout
(()
=>
{
setList
([
...
list
,
new
Date
().
getTime
()
])
setList
([
...
list
,
new
Date
().
getTime
()
,
new
Date
().
getTime
()
+
1
])
setRefreshState
(
RefreshState
.
Idle
)
setRefreshState
(
Refresh
List
State
.
Idle
)
},
1000
);
},
1000
);
}
}
console
.
log
(
list
)
return
(
return
(
<
View
style=
{
{
flex
:
1
}
}
>
<
View
style=
{
{
flex
:
1
}
}
>
<
RefreshListView
<
RefreshListView
data=
{
list
}
data=
{
list
}
keyExtractor=
{
(
index
:
number
)
=>
{
return
'key'
+
index
+
'key'
}
}
renderItem=
{
renderItem
}
renderItem=
{
renderItem
}
refreshState=
{
refreshState
}
state=
{
refreshState
}
onHeaderRefresh=
{
onHeaderRefresh
}
onHeaderRefresh=
{
onHeaderRefresh
}
onFooterRefresh=
{
onFooterRefresh
}
onFooterRefresh=
{
onFooterRefresh
}
footerRefreshingComponent=
{
<
View
style=
{
{
justifyContent
:
'center'
,
alignItems
:
'center'
}
}
>
<
Text
style=
{
{
color
:
'black'
}
}
>
loading...
</
Text
>
</
View
>
}
/>
/>
</
View
>
</
View
>
)
)
...
@@ -84,33 +82,24 @@ const ListView = (props: any) => {
...
@@ -84,33 +82,24 @@ const ListView = (props: any) => {
const
About
=
({
dispatch
,
...
otherProps
}:
AboutProps
)
=>
{
const
About
=
({
dispatch
,
...
otherProps
}:
AboutProps
)
=>
{
const
navigation
=
useNavigation
()
useHeaderShow
(
false
)
const
insets
=
useSafeAreaInsets
()
useHeaderShow
(
true
)
useEffect
(()
=>
{
console
.
log
(
otherProps
)
return
()
=>
{
console
.
log
(
'about destory'
)
}
},
[])
return
(
return
(
<
ScrollTabView
<
View
style=
{
{
flex
:
1
,
paddingTop
:
insets
.
top
,
backgroundColor
:
'#fff'
}
}
>
style=
{
{
margin
:
10
,
backgroundColor
:
'#f0f0f0'
,
overflow
:
'hidden'
}
}
<
TabListView
renderTabBar=
{
()
=>
<
ScrollableTabBar
/>
}
style=
{
{
margin
:
10
,
backgroundColor
:
'#f0f0f0'
,
overflow
:
'hidden'
}
}
>
tabBarPosition=
'top'
>
<
TabListItem
tabLabel=
'1'
>
<
Page1
tabLabel=
"React"
/>
<
Page1
/>
<
Page2
tabLabel=
"Flow"
/>
</
TabListItem
>
<
ListView
tabLabel=
"Jest"
/>
<
TabListItem
tabLabel=
'2'
>
</
ScrollTabView
>
<
ListView
/>
</
TabListItem
>
</
TabListView
>
</
View
>
)
)
}
}
About
.
options
=
{
headerShown
:
false
}
export
default
connect
(({
home
}:
any
)
=>
{
export
default
connect
(({
home
}:
any
)
=>
{
return
{
return
{
home
home
...
...
src/pages/home/index.tsx
View file @
bab4259c
import
React
,
{
useEffect
,
useState
}
from
'react'
import
React
,
{
useEffect
,
useState
,
useCallback
}
from
'react'
import
{
View
,
Text
,
Button
}
from
"react-native"
;
import
{
View
,
Text
,
Button
}
from
"react-native"
;
import
RefreshListView
,
{
RefreshListState
}
from
'@/components/refresh-list-view
'
import
{
RefreshListView
}
from
'@/components
'
import
{
TouchableHighlight
}
from
'react-native-gesture-handler'
;
import
{
TouchableHighlight
}
from
'react-native-gesture-handler'
;
import
navigate
from
'@/navigate'
;
import
navigate
from
'@/navigate'
;
import
{
useHeaderShow
}
from
'@/hooks'
;
import
{
useHeaderShow
}
from
'@/hooks'
;
...
@@ -13,6 +13,8 @@ import { PageProps } from 'global';
...
@@ -13,6 +13,8 @@ import { PageProps } from 'global';
// NoMoreData (已加载全部数据)
// NoMoreData (已加载全部数据)
// Failure (加载失败
// Failure (加载失败
const
{
RefreshListState
}
=
RefreshListView
const
Home
=
(
props
:
PageProps
)
=>
{
const
Home
=
(
props
:
PageProps
)
=>
{
useHeaderShow
(
true
)
useHeaderShow
(
true
)
...
@@ -40,7 +42,7 @@ const Home = (props: PageProps) => {
...
@@ -40,7 +42,7 @@ const Home = (props: PageProps) => {
</
TouchableHighlight
>
</
TouchableHighlight
>
)
)
const
onHeaderRefresh
=
(
state
:
RefreshListState
)
=>
{
const
onHeaderRefresh
=
(
state
)
=>
{
setRefreshState
(
RefreshListState
.
HeaderRefreshing
)
setRefreshState
(
RefreshListState
.
HeaderRefreshing
)
console
.
log
(
'onHeaderRefresh'
)
console
.
log
(
'onHeaderRefresh'
)
setTimeout
(()
=>
{
setTimeout
(()
=>
{
...
@@ -49,14 +51,14 @@ const Home = (props: PageProps) => {
...
@@ -49,14 +51,14 @@ const Home = (props: PageProps) => {
},
1000
);
},
1000
);
}
}
const
onFooterRefresh
=
(
state
:
RefreshListState
)
=>
{
const
onFooterRefresh
=
(
state
)
=>
{
console
.
log
(
'onHeaderRefresh: '
,
state
,
RefreshListState
.
FooterRefreshing
)
if
(
state
===
RefreshListState
.
FooterRefreshing
||
list
.
length
>
10
)
{
if
(
state
===
RefreshListState
.
FooterRefreshing
)
{
setRefreshState
(
RefreshListState
.
NoMoreData
)
return
return
}
}
setRefreshState
(
RefreshListState
.
FooterRefreshing
)
setRefreshState
(
RefreshListState
.
FooterRefreshing
)
setTimeout
(()
=>
{
setTimeout
(()
=>
{
setList
([
...
list
,
new
Date
().
getTime
()
])
setList
([
...
list
,
new
Date
().
getTime
()
,
new
Date
().
getTime
()
+
1
])
setRefreshState
(
RefreshListState
.
Idle
)
setRefreshState
(
RefreshListState
.
Idle
)
},
1000
);
},
1000
);
}
}
...
...
src/utils/index.ts
0 → 100644
View file @
bab4259c
import
{
Dimensions
}
from
"react-native"
export
const
rpx
=
(
rpx
:
number
)
=>
{
return
Dimensions
.
get
(
'window'
).
width
/
375.0
*
rpx
}
\ No newline at end of file
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