Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekLearnMathWeapp
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
frontend
GeekLearnMathWeapp
Commits
4791f652
Commit
4791f652
authored
Mar 27, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tag animate
parent
7b758342
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
5 deletions
+80
-5
constants.ts
src/pages/main/components/scene/constants.ts
+3
-0
round-tag.tsx
src/pages/main/components/scene/round-tag.tsx
+64
-0
round.tsx
src/pages/main/components/scene/round.tsx
+9
-4
short-cut.tsx
src/pages/main/components/short-cut.tsx
+1
-0
main.tsx
src/pages/main/main.tsx
+3
-1
No files found.
src/pages/main/components/scene/constants.ts
View file @
4791f652
import
assets
from
'@/assets/oss/assets-main'
import
{
createContext
}
from
'react'
export
const
SceneContext
=
createContext
<
{
ready
:
boolean
}
>
({
ready
:
false
})
export
type
ImageSource
=
{
w
:
number
;
...
...
src/pages/main/components/scene/round-tag.tsx
0 → 100644
View file @
4791f652
import
{
Image
}
from
'@tarojs/components'
import
{
useEffect
,
useState
,
useRef
,
useMemo
}
from
'react'
import
{
usePageScroll
,
createIntersectionObserver
,
getCurrentInstance
,
getMenuButtonBoundingClientRect
}
from
'@tarojs/taro'
type
RoundTagProps
=
{
url
:
string
;
className
:
string
;
id
:
number
|
string
;
ready
:
boolean
;
}
const
RoundTag
=
(
props
:
RoundTagProps
)
=>
{
const
nav
=
useRef
(
getMenuButtonBoundingClientRect
())
const
page
=
useMemo
(()
=>
getCurrentInstance
().
page
,
[])
const
{
url
,
className
,
id
,
ready
}
=
props
const
scrollRef
=
useRef
(
0
)
const
lastEffectedScroll
=
useRef
(
0
)
usePageScroll
(
payload
=>
{
scrollRef
.
current
=
payload
.
scrollTop
})
const
uid
=
useMemo
(()
=>
`tag_
${
id
}
`
,
[
id
])
useEffect
(()
=>
{
let
observer
if
(
ready
)
{
lastEffectedScroll
.
current
=
scrollRef
.
current
const
navVal
=
nav
.
current
observer
=
(
createIntersectionObserver
as
any
)().
relativeToViewport
({
bottom
:
0
,
top
:
-
navVal
.
height
-
navVal
.
top
-
5
})
.
observe
(
`#
${
uid
}
`
,
({
intersectionRatio
})
=>
{
const
show
=
intersectionRatio
>
0
const
isDown
=
lastEffectedScroll
.
current
<
scrollRef
.
current
if
(
show
&&
!
isDown
)
{
page
?.
animate
?.(
`#
${
uid
}
`
,
[
{
opacity
:
0
,
translateY
:
20
,
scale
:
[
1
,
1
]
},
{
opacity
:
1
,
translateY
:
0
,
scale
:
[
1
,
1
]
},
{
opacity
:
1
,
translateY
:
0
,
scale
:
[
1.2
,
1.2
],
offset
:
0.8
},
{
opacity
:
1
,
translateY
:
0
,
scale
:
[
1
,
1
]
},
],
1200
,
()
=>
{
page
?.
clearAnimation
?.(
`#
${
uid
}
`
,
()
=>
{})
})
}
lastEffectedScroll
.
current
=
scrollRef
.
current
})
}
return
()
=>
{
if
(
observer
)
{
observer
.
disconnect
()
observer
=
null
}
}
},
[
uid
,
ready
,
page
])
return
(
<
Image
src=
{
url
}
className=
{
className
}
id=
{
uid
}
></
Image
>
)
}
export
default
RoundTag
src/pages/main/components/scene/round.tsx
View file @
4791f652
import
{
View
,
Image
}
from
'@tarojs/components'
import
assets
from
'@/assets/oss/assets-round'
import
classNames
from
'classnames'
import
{
RoundState
,
type
Round
,
RoundType
,
type
ImageSource
,
RoundScore
,
CurrentRoundId
}
from
'./constants'
import
{
RoundState
,
type
Round
,
RoundType
,
type
ImageSource
,
RoundScore
,
CurrentRoundId
,
SceneContext
}
from
'./constants'
import
RoundTag
from
'./round-tag'
import
styles
from
'./round.module.scss'
...
...
@@ -99,7 +100,7 @@ const getIconClassNames = (type?: RoundType, extra: string[] = []) => {
const
RoundComp
=
(
props
:
RoundProps
)
=>
{
const
{
round
}
=
props
const
renderRound
=
()
=>
{
const
renderRound
=
(
ready
:
boolean
)
=>
{
switch
(
round
.
state
)
{
case
RoundState
.
Locked
:
{
return
(
...
...
@@ -118,7 +119,7 @@ const RoundComp = (props: RoundProps) => {
return
(
<
View
className=
{
styles
.
clear
}
>
{
!!
tag
&&
(
<
Image
src=
{
tag
.
u
}
className=
{
styles
.
tag
}
></
Image
>
<
RoundTag
url=
{
tag
.
u
}
className=
{
styles
.
tag
}
id=
{
round
.
id
}
ready=
{
ready
}
/
>
)
}
<
Image
src=
{
getScoreIcon
(
round
.
score
).
u
}
className=
{
styles
.
score
}
/>
<
Image
src=
{
getClearIcon
(
round
.
type
).
u
}
className=
{
getIconClassNames
(
round
.
type
,
[
styles
.
clearIcon
])
}
/>
...
...
@@ -139,10 +140,14 @@ const RoundComp = (props: RoundProps) => {
}
return
(
<
SceneContext
.
Consumer
>
{
({
ready
})
=>
(
<
View
className=
{
props
.
className
}
id=
{
round
.
state
===
RoundState
.
UnLocked
?
CurrentRoundId
:
undefined
}
>
{
renderRound
(
)
}
{
renderRound
(
ready
)
}
<
View
className=
{
styles
.
roundName
}
>
{
round
.
name
}
</
View
>
</
View
>
)
}
</
SceneContext
.
Consumer
>
)
}
...
...
src/pages/main/components/short-cut.tsx
View file @
4791f652
...
...
@@ -22,6 +22,7 @@ const ShortCut = (props: ShortCutProps) => {
})
useEffect
(()
=>
{
lastEffectedScroll
.
current
=
scrollRef
.
current
let
observer
=
(
createIntersectionObserver
as
any
)().
relativeToViewport
({
bottom
:
0
})
.
observe
(
`#
${
CurrentRoundId
}
`
,
({
intersectionRatio
})
=>
{
const
show
=
intersectionRatio
>
0
...
...
src/pages/main/main.tsx
View file @
4791f652
import
{
View
}
from
'@tarojs/components'
import
{
getMenuButtonBoundingClientRect
,
useDidShow
,
getCurrentInstance
,
getTabBar
,
pageScrollTo
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
useState
,
useMemo
,
useEffect
,
useCallback
}
from
'react'
import
{
CurrentRoundId
}
from
'./components/scene/constants'
import
{
CurrentRoundId
,
SceneContext
}
from
'./components/scene/constants'
import
MainHeader
from
'./components/header'
import
MainChapter
from
'./components/chapter'
import
MainScene
from
'./components/scene'
...
...
@@ -41,7 +41,9 @@ const MainPage = () => {
<
MainHeader
/>
<
View
className=
{
styles
.
body
}
style=
{
{
paddingTop
:
`${nav.height + nav.top + 5}px`
}
}
>
<
MainChapter
/>
<
SceneContext
.
Provider
value=
{
{
ready
:
isReady
}
}
>
<
MainScene
/>
</
SceneContext
.
Provider
>
<
View
className=
{
styles
.
gap
}
></
View
>
</
View
>
{
isReady
&&
(
...
...
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