Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

onTap event doesn't work with onLongPress #6

Open
sebastianingino opened this issue Dec 24, 2016 · 2 comments
Open

onTap event doesn't work with onLongPress #6

sebastianingino opened this issue Dec 24, 2016 · 2 comments

Comments

@sebastianingino
Copy link

I have a view that when it's tapped, it does something, but when it's long-pressed, it enables dragging. The tap event isn't working with the drag constraints. Nothing happens when tapped under these conditions:

# Imports
Font 'Roboto', '500,400,300'

# Starting Vars & Functions
lights = false

lightLevel = 0

longPress = false

screen =
	height: App.height
	width: App.height*(17/30)

if App.height*(17/30)-1 > App.width
	screen =
		height: App.width*(30/17)
		width: App.width

globalConvertX = (x) ->
	return x*(screen.height/300)

globalConvertY = (x) ->
		return x*(screen.width/170)

# Create page
App.page = new Page
	backgroundColor: '#0F0F3B'

# Object Background View
background = new View
	width: globalConvertY(120)
	height: globalConvertX(250)
	backgroundColor: white
	borderRadius: globalConvertX(5)
	shadowY: globalConvertY(3)
	shadowBlur: globalConvertX(6)
	shadowColor: 'rgba(0,0,0,0.4)'

background.center()
background.clip = yes

# Slider View
slider = new View
	width: globalConvertY(140)
	height: globalConvertX(33)
	backgroundColor: '#40BFC9'
	borderRadius: globalConvertX(4)
	shadowY: globalConvertY(3)
	shadowBlur: globalConvertX(6)
	shadowColor: 'rgba(0,0,0,0.4)'
	transition:
		duration: 0.2
		curve: 'cubic-out'

slider.centerX()
slider.clip = yes
slider.y = globalConvertY(222)
slider.draggable.enabled = no
slider.draggable.horizontal = no
slider.draggable.vertical = yes
slider.draggable.momentumOptions =
	friction: 15
slider.draggable.overdragScale = 0.1
slider.draggable.constraints =
	y: (App.height - (globalConvertX(250) - globalConvertY(40)))/2
	height: globalConvertX(250) - globalConvertY(40)
	width: App.widths
slider.draggable.bounceOptions =
	friction: 25
	tension: 300
slider.draggable.directionLock = yes
slider.draggable.directionLockThreshold =
   y: 0
	 x: 1000


# Event Listening
background.onTap (event) ->
	if lights == true
		lights = false
		lightLevel = 100
	else
		lights = true
		lightLevel = 0
	slider.animate
		y: globalConvertY((lightLevel*1.77)+45)
		time: 0.2
		curve: 'spring(300, 25)'

slider.onLongPress (event) ->
	slider.draggable.enabled = yes
	slider.animate
		shadowY: globalConvertY(6)
		shadowBlur: globalConvertX(12)
		shadowColor: 'rgba(0,0,0,0.5)'
		time: 0.15
		curve: 'cubic-out'

slider.onLongPressEnd (event) ->
	slider.draggable.enabled = no
	slider.animate
		shadowY: globalConvertY(3)
		shadowBlur: globalConvertX(6)
		shadowColor: 'rgba(0,0,0,0.4)'
		time: 0.15
		curve: 'cubic-out'

slider.onTap (event) ->
	if lights == true
		lights = false
		lightLevel = 100
	else
		lights = true
		lightLevel = 0
	slider.animate
		y: globalConvertY((lightLevel*1.77)+45)
		time: 0.2
		curve: 'spring(300, 25)'

If you remove the drag constraints, it works just fine, but I need the constraints. What's not working?

@sebastianingino
Copy link
Author

Examples:
Not working with code above: https://magixjs.com/1yojsh (Tapping the slider, not the bg)
Working but without drag constraints: https://magixjs.com/thtykf

@etiennepinchon
Copy link
Owner

Okay sorry for the wait, I had to take a short break from code for christmas lol
I am on the case, I let you know asap ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants