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
Hide 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>) => {
const
handleOnFooterRefresh
=
()
=>
{
onFooterRefresh
&&
onFooterRefresh
(
state
)
}
return
(
<
RefreshListView
data=
{
data
}
keyExtractor=
{
(
index
:
number
)
=>
{
return
'key'
+
index
+
'key'
}
}
renderItem=
{
r
enderItem
}
renderItem=
{
handleR
enderItem
}
refreshState=
{
state
}
onHeaderRefresh=
{
handleOnHeaderRefresh
}
onFooterRefresh=
{
handleOnFooterRefresh
}
...
...
@@ -60,4 +59,6 @@ const FlastView = (props: RrefreshListProps<any>) => {
)
}
FlastView
.
RefreshListState
=
RefreshListState
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
{
View
,
Text
,
TouchableHighlight
}
from
"react-native"
;
import
{
useNavigation
,
NavigationProp
}
from
'@react-navigation/native'
;
import
{
connect
}
from
'react-redux'
;
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'
;
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
=
{
dispatch
:
Dispatch
,
...
...
@@ -18,65 +20,61 @@ 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
ListView
=
(
props
:
any
)
=>
{
const
[
list
,
setList
]
=
useState
([
1
,
2
,
3
])
const
[
refreshState
,
setRefreshState
]
=
useState
(
RefreshState
.
Idle
)
const
[
refreshState
,
setRefreshState
]
=
useState
(
RefreshListState
.
Idle
)
const
navigation
=
useNavigation
()
useEffect
(()
=>
{
console
.
log
(
props
)
const
handleFocus
=
()
=>
{
props
.
navigation
}
navigation
.
addListener
(
'focus'
,
handleFocus
)
return
()
=>
{
navigation
.
removeListener
(
'focus'
,
handleFocus
)
}
},
[])
const
renderItem
=
(
itm
:
any
)
=>
(
<
TouchableHighlight
underlayColor=
'#f5f5f5'
onPress=
{
()
=>
{
navigate
.
navigateAbout
()
}
}
>
<
View
style=
{
{
margin
Bottom
:
15
,
backgroundColor
:
'yellow'
}
}
>
<
View
style=
{
{
margin
:
10
,
backgroundColor
:
'yellow'
}
}
>
<
Text
style=
{
{
color
:
'red'
}
}
>
{
JSON
.
stringify
(
itm
)
}
</
Text
>
</
View
>
</
TouchableHighlight
>
)
const
onHeaderRefresh
=
()
=>
{
setRefreshState
(
RefreshState
.
HeaderRefreshing
)
const
onHeaderRefresh
=
(
state
)
=>
{
setRefreshState
(
RefreshListState
.
HeaderRefreshing
)
console
.
log
(
'onHeaderRefresh'
)
setTimeout
(()
=>
{
setList
([
1
,
2
,
3
])
setRefreshState
(
RefreshState
.
Idle
)
setRefreshState
(
Refresh
List
State
.
Idle
)
},
1000
);
}
const
onFooterRefresh
=
()
=>
{
console
.
log
(
'onFooterRefresh'
)
setRefreshState
(
RefreshState
.
FooterRefreshing
)
if
(
list
.
length
>=
5
)
{
setRefreshState
(
RefreshState
.
NoMoreData
)
const
onFooterRefresh
=
(
state
)
=>
{
if
(
state
===
RefreshListState
.
FooterRefreshing
||
list
.
length
>
10
)
{
setRefreshState
(
RefreshListState
.
NoMoreData
)
return
}
setRefreshState
(
RefreshListState
.
FooterRefreshing
)
setTimeout
(()
=>
{
setList
([
...
list
,
new
Date
().
getTime
()
])
setRefreshState
(
RefreshState
.
Idle
)
setList
([
...
list
,
new
Date
().
getTime
()
,
new
Date
().
getTime
()
+
1
])
setRefreshState
(
Refresh
List
State
.
Idle
)
},
1000
);
}
console
.
log
(
list
)
return
(
<
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
>
)
...
...
@@ -84,33 +82,24 @@ const ListView = (props: any) => {
const
About
=
({
dispatch
,
...
otherProps
}:
AboutProps
)
=>
{
const
navigation
=
useNavigation
()
useHeaderShow
(
true
)
useEffect
(()
=>
{
console
.
log
(
otherProps
)
return
()
=>
{
console
.
log
(
'about destory'
)
}
},
[])
useHeaderShow
(
false
)
const
insets
=
useSafeAreaInsets
()
return
(
<
ScrollTabView
style=
{
{
margin
:
10
,
backgroundColor
:
'#f0f0f0'
,
overflow
:
'hidden'
}
}
renderTabBar=
{
()
=>
<
ScrollableTabBar
/>
}
tabBarPosition=
'top'
>
<
Page1
tabLabel=
"React"
/>
<
Page2
tabLabel=
"Flow"
/>
<
ListView
tabLabel=
"Jest"
/>
</
ScrollTabView
>
<
View
style=
{
{
flex
:
1
,
paddingTop
:
insets
.
top
,
backgroundColor
:
'#fff'
}
}
>
<
TabListView
style=
{
{
margin
:
10
,
backgroundColor
:
'#f0f0f0'
,
overflow
:
'hidden'
}
}
>
<
TabListItem
tabLabel=
'1'
>
<
Page1
/>
</
TabListItem
>
<
TabListItem
tabLabel=
'2'
>
<
ListView
/>
</
TabListItem
>
</
TabListView
>
</
View
>
)
}
About
.
options
=
{
headerShown
:
false
}
export
default
connect
(({
home
}:
any
)
=>
{
return
{
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
RefreshListView
,
{
RefreshListState
}
from
'@/components/refresh-list-view
'
import
{
RefreshListView
}
from
'@/components
'
import
{
TouchableHighlight
}
from
'react-native-gesture-handler'
;
import
navigate
from
'@/navigate'
;
import
{
useHeaderShow
}
from
'@/hooks'
;
...
...
@@ -13,6 +13,8 @@ import { PageProps } from 'global';
// NoMoreData (已加载全部数据)
// Failure (加载失败
const
{
RefreshListState
}
=
RefreshListView
const
Home
=
(
props
:
PageProps
)
=>
{
useHeaderShow
(
true
)
...
...
@@ -40,7 +42,7 @@ const Home = (props: PageProps) => {
</
TouchableHighlight
>
)
const
onHeaderRefresh
=
(
state
:
RefreshListState
)
=>
{
const
onHeaderRefresh
=
(
state
)
=>
{
setRefreshState
(
RefreshListState
.
HeaderRefreshing
)
console
.
log
(
'onHeaderRefresh'
)
setTimeout
(()
=>
{
...
...
@@ -49,14 +51,14 @@ const Home = (props: PageProps) => {
},
1000
);
}
const
onFooterRefresh
=
(
state
:
RefreshListState
)
=>
{
console
.
log
(
'onHeaderRefresh: '
,
state
,
RefreshListState
.
FooterRefreshing
)
if
(
state
===
RefreshListState
.
FooterRefreshing
)
{
const
onFooterRefresh
=
(
state
)
=>
{
if
(
state
===
RefreshListState
.
FooterRefreshing
||
list
.
length
>
10
)
{
setRefreshState
(
RefreshListState
.
NoMoreData
)
return
}
setRefreshState
(
RefreshListState
.
FooterRefreshing
)
setTimeout
(()
=>
{
setList
([
...
list
,
new
Date
().
getTime
()
])
setList
([
...
list
,
new
Date
().
getTime
()
,
new
Date
().
getTime
()
+
1
])
setRefreshState
(
RefreshListState
.
Idle
)
},
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