Skip to content

Commit 33dd1e4

Browse files
committed
minor fixes
1 parent 4e4cb8c commit 33dd1e4

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/drawer/snapped-drawer/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class SnappedDrawer {
2727
this._target = options.TARGET
2828
this._handlers = null
2929
this._direction = options.DIRECTION
30-
this._callibration = null
30+
this._calibration = null
3131
this._callbacks = null
3232
this._context = this
3333
this._id = 0
@@ -58,25 +58,25 @@ export default class SnappedDrawer {
5858

5959
const startHandler = (touchEvent) => {
6060
const activity = this._drawerManager.getRunningActivity()
61-
if (this._callibration &&
61+
if (this._calibration &&
6262
(this._id && activity && activity.id === this._id ||
6363
!activity && this._isCoolSignal(this._getSignal(touchEvent)))) {
64-
this._callibration.start(touchEvent, startfn)
64+
this._calibration.start(touchEvent, startfn)
6565
}
6666
}
6767

6868
const moveHandler = (touchEvent) => {
6969
const activity = this._drawerManager.getRunningActivity()
70-
if (this._callibration && activity && activity.id === this._id) {
71-
this._callibration.move(touchEvent, movefn)
70+
if (this._calibration && activity && activity.id === this._id) {
71+
this._calibration.move(touchEvent, movefn)
7272
}
7373
}
7474

7575
const endHandler = (touchEvent) => {
7676
const activity = this._drawerManager.getRunningActivity()
77-
if (this._callibration && activity && activity.id === this._id) {
77+
if (this._calibration && activity && activity.id === this._id) {
7878
const state = {}
79-
this._callibration.end(touchEvent, endfn, state) // state by Ref
79+
this._calibration.end(touchEvent, endfn, state) // state by Ref
8080
this._processThresholdState(state)
8181
}
8282
}
@@ -149,7 +149,7 @@ export default class SnappedDrawer {
149149

150150
setContext(ctx) {
151151
this._context = ctx
152-
this._callibration.setContext(ctx)
152+
this._calibration.setContext(ctx)
153153
return this
154154
}
155155

@@ -182,24 +182,24 @@ export default class SnappedDrawer {
182182
_setCalibration(point, bound) {
183183
switch (point) {
184184
case SnappedDrawer.UP:
185-
this._callibration = new Top(this._options, bound)
185+
this._calibration = new Top(this._options, bound)
186186
break
187187
case SnappedDrawer.LEFT:
188-
this._callibration = new Left(this._options, bound)
188+
this._calibration = new Left(this._options, bound)
189189
break
190190
case SnappedDrawer.DOWN:
191-
this._callibration = new Bottom(this._options, bound)
191+
this._calibration = new Bottom(this._options, bound)
192192
break
193193
case SnappedDrawer.RIGHT:
194-
this._callibration = new Right(this._options, bound)
194+
this._calibration = new Right(this._options, bound)
195195
break
196196
default:
197197
throw RangeError('Direction out of range')
198198
}
199199
}
200200

201201
_isCoolSignal(signal) {
202-
const size = this._direction === SnappedDrawer.UP || this._direction === SnappedDrawer.DOWN ? WINDOW.screen.availHeight : WINDOW.screen.availWidth
202+
const size = this._direction === SnappedDrawer.UP || this._direction === SnappedDrawer.DOWN ? WINDOW.screen.height : WINDOW.screen.width
203203
switch (this._direction) {
204204
case SnappedDrawer.UP:
205205
case SnappedDrawer.LEFT:
@@ -238,7 +238,6 @@ export default class SnappedDrawer {
238238
}
239239
}
240240

241-
// private
242241
_register(...handlers) {
243242
this._handlers = handlers
244243
}

src/nav/drawer.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const KILO = 1e3
1515
const MIN_TIME_TO_OVERRIDE_BELOWTHRESHOLD = 0.5
1616
const MIN_POSITIVE_DISPLACEMENT = 10
1717
const MIN_NEGATIVE_DISPLACEMENT = -MIN_POSITIVE_DISPLACEMENT
18-
const TRANSITION_STYLE = 'linear'
18+
const TRANSITION_STYLE = 'linear'// 'cubic-bezier(0, 0.5, 0, 1)'
1919
const EFFECT = 'transition'
2020
const OVERFLOW = 'overflow'
2121
const TRANS_TIMING = '0.1s'
@@ -29,7 +29,7 @@ const START = 'start'
2929
const MOVE = 'move'
3030
const THRESHOLD = 'threshold'
3131
const BELOW_THRESHOLD = `below${THRESHOLD}`
32-
const MAX_TIME = KILO
32+
const MIN_SPEED = 100
3333
const MAX_SPEED = 500
3434

3535
class NavDrawer {
@@ -94,7 +94,7 @@ class NavDrawer {
9494
get _bound() {
9595
const upperBound = this.elementSize
9696
if (this.direction === Drawer.RIGHT) {
97-
const lowerBound = WINDOW.screen.availWidth - this.element.offsetLeft
97+
const lowerBound = WINDOW.screen.width - this.element.offsetLeft
9898
return new Bound(lowerBound, upperBound)
9999
}
100100
const lowerBound = upperBound + this.element.offsetLeft
@@ -121,20 +121,20 @@ class NavDrawer {
121121
[OVERFLOW]: HIDDEN
122122
})
123123
if (this.direction === Drawer.RIGHT) {
124-
const WIN_SIZE = WINDOW.screen.availWidth
124+
const WIN_SIZE = WINDOW.screen.width
125125
curPos = WIN_SIZE - curPos
126126
this._backdrop.setOpacity(curPos / this.elementSize)
127127
return
128128
}
129129
this._backdrop.setOpacity(curPos / this.elementSize)
130130
}
131131

132-
_threshold(service, state, stateObj) {
132+
_threshold(service, state, stateObj, rect) {
133133
service.lock()
134134
const isOpen = state[1] === 'open'
135135
const options = {
136136
stateObj,
137-
transition: `${this.directionString} ease ${this._calcSpeed(stateObj.TIMING) / KILO}s`
137+
transition: `${this.directionString} ${TRANSITION_STYLE} ${this._calcSpeed(stateObj.TIMING, rect.width) / KILO}s`
138138
}
139139
if (isOpen) {
140140
this._hide(options)
@@ -154,7 +154,7 @@ class NavDrawer {
154154
? rect.displacementY : rect.displacementX
155155
const options = {
156156
stateObj,
157-
transition: `${this.directionString} ease ${this._calcSpeed(stateObj.TIMING) / KILO}s`
157+
transition: `${this.directionString} ${TRANSITION_STYLE} ${this._calcSpeed(stateObj.TIMING, rect.width) / KILO}s`
158158
}
159159
let LOGIC
160160
if (this.direction === Drawer.LEFT && isClosed || this.direction === Drawer.RIGHT && !isClosed) {
@@ -242,13 +242,18 @@ class NavDrawer {
242242
}
243243
}
244244

245-
_calcSpeed(time) {
246-
if (time >= MAX_TIME) {
247-
return MAX_SPEED
245+
_calcSpeed(time, distance) {
246+
const distanceRemain = this.elementSize - distance
247+
if (~Math.sign(distanceRemain)) {
248+
let newTime = distanceRemain * time / distance
249+
if (newTime > MAX_SPEED) {
250+
newTime = MAX_SPEED
251+
} else if (newTime < MIN_SPEED) {
252+
newTime = MIN_SPEED
253+
}
254+
return newTime
248255
}
249-
const percent = 100
250-
const percentage = time / MAX_TIME * percent
251-
return percentage / percent * MAX_SPEED
256+
return 0
252257
}
253258

254259
_checkDirection() {

src/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ export function getData(el, dataName) {
136136
}
137137

138138
export function offsetRight(el) {
139-
return WINDOW.screen.availWidth - el.offsetLeft - el.offsetWidth
139+
return WINDOW.screen.width - el.offsetLeft - el.offsetWidth
140140
}
141141

142142
export function offsetBottom(el) {
143-
return WINDOW.screen.availHeight - el.offsetTop - el.offsetHeight
143+
return WINDOW.screen.height - el.offsetTop - el.offsetHeight
144144
}
145145

146146
export function resolveThreshold(threshold) {

0 commit comments

Comments
 (0)