Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
wmatt
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
Accepted Solution

onSwipeDown problem

[ Edited ]

I'm converting my app from AIR to WebWorks (TabletOS 2.2.0.5), but I can't get the onSwipeDown event working. This is the test code I'm trying to figure out:

 

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=1024,height=600,initial-scale=1.0,user-scalable=no" />
<title>Untitled Document</title>
<script type="text/javascript">
var load = function () {
	blackberry.app.event.onSwipeDown(alertSwipe);
	var alertSwipe = function() {
		alert("swipe");
	};
};
</script>
</head>
<body onLoad="load()">
</body>
</html>

 and config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
        version="0.0.0.1" id="SwipeDemo">  
    <name>Swipe Demo</name>
    <author>Matt</author>
    <description>Test</description>
    <icon src="assets/images/launchicon.png"/>
    <content src="index.html"/>
    <feature id="blackberry.app.event"/>
</widget>
Please use plain text.
Developer
wmatt
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook

Re: onSwipeDown problem

[ Edited ]

I just tried it with TabletOS 2.1.0.6 SDK. So I'm doing something wrong here.

Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 620
Registered: ‎10-01-2009
My Device: Z10

Re: onSwipeDown problem

Hello,

 

Check out the Knowledge Base article on this, it should help get you going in the right direction.  http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Sample-Code-Swipe-down-menu-for-...

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: onSwipeDown problem

You may have read this already:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Sample-Code-Swipe-down-menu-for-...

 

On that link there is a swipemenu.js that may be useful to you:

https://github.com/blackberry/WebWorks-Samples/tree/master/swipemenu

 

Apart from that your code looks right.

If it helped you, click like. :smileyhappy:
Please use plain text.
Developer
wmatt
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook

Re: onSwipeDown problem

[ Edited ]

Thanks, I got it working from that example. I don't know why, but I needed to register the event inside an if statement. Any idea what the reason is? 

 

This is code works

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=1024,height=600,initial-scale=1.0,user-scalable=no" />
<title>Untitled Document</title>
<script type="text/javascript">
var alertSwipe = function () {
  alert("swipe");
};
var load = function () {
  if ((typeof window.blackberry !== "undefined") && (typeof blackberry.app !== "undefined")) {
    blackberry.app.event.onSwipeDown(alertSwipe);
  }
}
</script>
</head>
<body onLoad="load()">
</body>
</html>

 

 

Please use plain text.
Developer
jamesgibbons
Posts: 26
Registered: ‎06-01-2010
My Device: Dev Alpha, PlayBook

Re: onSwipeDown problem

In your original code you save the alertSwipe function to a variable after trying to call it. If you define the variable before calling it, then it should work. Here is the code:

 

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=1024,height=600,initial-scale=1.0,user-scalable=no" />
<title>Untitled Document</title>
<script type="text/javascript">
var load = function () {
	var alertSwipe = function() {
		alert("swipe");
	};
	blackberry.app.event.onSwipeDown(alertSwipe);
	
	
};
</script>
</head>
<body onLoad="load()">
</body>
</html>

 Alternately, if you hadn't saved the function to a variable, the code should have worked:

 

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=1024,height=600,initial-scale=1.0,user-scalable=no" />
<title>Untitled Document</title>
<script type="text/javascript">
var load = function () {
	
	blackberry.app.event.onSwipeDown(alertSwipe);
	function alertSwipe() {
		alert("swipe");
	};
	
	
};
</script>
</head>
<body onLoad="load()">
</body>
</html>

 Hope this helps! :smileyhappy:

 

 

___________________________________________________________
My latest Blackberry 10 app Audiobooks! :smileyhappy:

My latest PlayBook app Photojam!

Find me on Twitter: GoGibbons
Please use plain text.