8000 Apply direction classes to navigation lifecycle. by domchristie · Pull Request #16 · domchristie/turn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Apply direction classes to navigation lifecycle. #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
7 changes: 6 additions & 1 deletion src/animation-turn.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default class AnimationTurn extends BaseTurn {
this.dispatch('before-exit', { detail })

window.requestAnimationFrame(() => {
exitAnimations.start(() => this.addClasses('exit'))
exitAnimations.start(() => {
this.addClasses(this.direction)
this.addClasses('exit')
})
this.removeClasses('before-exit')
resolveExit()
})
Expand All @@ -43,13 +46,15 @@ export default class AnimationTurn extends BaseTurn {

async complete (detail) {
this.removeClasses('enter')
this.removeClasses(this.direction)
this.dispatch('enter', { detail: { ...detail, action: this.action } })
}

abort () {
this.removeClasses('before-exit')
this.removeClasses('exit')
this.removeClasses('enter')
this.removeClasses(this.direction)
}

get finished () {
Expand Down
6 changes: 5 additions & 1 deletion src/base-turn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ const DEFAULT_OPTIONS = {
}

export default class BaseTurn {
constructor (action, options = {}) {
constructor (action, direction = 'none', options = {}) {
this.action = action
this.direction = direction
this.options = { ...DEFAULT_OPTIONS, ...options }
this.beforeExitClasses = new Set()
this.exitClasses = new Set()
this.enterClasses = new Set()
this.beforeTransitionClasses = new Set()
this.transitionClasses = new Set()
this.forwardClasses = new Set()
this.backClasses = new Set()
this.noneClasses = new Set()
}

addClasses (type) {
Expand Down
8 changes: 4 additions & 4 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default class Controller {
visit (event) {
this.reset(event)

this.animationTurn = create(AnimationTurn, event.detail.action)
this.viewTransitionTurn = create(ViewTransitionTurn, event.detail.action)
this.animationTurn = create(AnimationTurn, event.detail.action, event.detail.direction)
this.viewTransitionTurn = create(ViewTransitionTurn, event.detail.action, event.detail.direction)

this.animationTurn.exit({
...event.detail,
Expand Down Expand Up @@ -132,10 +132,10 @@ function removeActionClasses () {
classList.remove.apply(classList, ACTIONS.map(a => `turn-${a}`))
}

function create (Klass, action) {
function create (Klass, action, direction) {
if (!Klass.supported || document.body.dataset.turn === 'false') {
Klass = NullTurn
}
const options = JSON.parse(document.body.dataset.turnOptions || '{}')
return new Klass(action, options)
return new Klass(action, direction, options)
}
1 change: 1 addition & 0 deletions src/null-turn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default class NullTurn {
static supported = true
direction = 'none'
exit () {}
async beforeEnter () {}
async enter () {}
Expand Down
0