BackSwipe Navigation for Composer

614
Vote up!

iOS 7 style back swipe navigation library with demonstration app. Includes a template scene file.

The app loads from the main.lua and the first screen is home.lua
Each screen has buttons to navigate from "Page 1" through to "Page 3."
There is an intermediate screen called "Download" to demonstrate inserting screens which are not part of the swipe back navigation.

The supporting files are:
backswipelib.lua - Extends the composer api to enable backswipe navigation.
buttonlib.lua - Provides button creation functions used in each scene.
basicscene.lua - Revised version of the CoronaLabs Composer template scene.

To indicate that a scene will be back-swipe navigable include these values in the gotoScene options table:
{ effect="iosSlideLeft", isBackSwipe=true }

When a scene will want to provide backward navigation it must also set the name of the scene that back-swipe navigation will goto. Do this in the show event did phase:
function scene:show( event )
if (event.phase == "will") then
elseif (event.phase == "did") then
composer.setPreviousScene( "page1" )
end
end

To perform a backward navigation call gotoScene with these values in the options table:
{ effect="iosSlideRight", isBackSwipe=true }

To respond to a backswipe navigation event listen for the "swipe" event and perform the same navigation as in the Back button navigation:
function scene:swipe( event )
if (event.phase == "ended") then
composer.gotoScene( sceneName, { time=500, effect="iosSlideRight", isBackSwipe=true } )
end
end
scene:addEventListener( "swipe", scene )

Works with Corona build #: 
2014.2393
Category: 
Contributor: 
HoraceBury