Created
May 29, 2019 13:37
-
-
Save adamtarmstrong/bf724d31d138b73fb79f66a046ddbed3 to your computer and use it in GitHub Desktop.
Use SplitWindow w/ Titanium and toggle MasterView based on both orientation + if in SplitView/SplitOver Mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//XML | |
<Alloy> | |
<SplitWindow id="splitWindow" backgroundColor="white" showMasterInPortrait="true" masterIsOverlayed="true" platform="ios"> | |
<!--MASTER--> | |
<NavigationWindow platform="ios"> | |
<Window title="Master" layout="vertical"> | |
<LeftNavButtons> | |
<Label id="masterCollapseButton" class="navButton" text="<<" onClick="toggleMaster" /> | |
</LeftNavButtons> | |
<Label text="Master View" /> | |
</Window> | |
</NavigationWindow> | |
<!--DETAIL--> | |
<NavigationWindow platform="ios" id="detailNavWindow"> | |
<Window title="Detail" id="detailWindow" class="container" layout="vertical" backgroundColor="#cccccc"> | |
<LeftNavButtons> | |
<Label id="masterOpenButton" class="navButton" text=">>" onClick="toggleMaster" /> | |
</LeftNavButtons> | |
<Label text="Detail View" /> | |
</Window> | |
</NavigationWindow> | |
</SplitWindow> | |
</Alloy> | |
//JS | |
var showMaster = true; | |
Alloy.Globals.deviceSmallestMeasurement = (parseInt(Ti.Platform.displayCaps.platformWidth) < parseInt(Ti.Platform.displayCaps.platformHeight)) ? parseInt(Ti.Platform.displayCaps.platformWidth) : parseInt(Ti.Platform.displayCaps.platformHeight); | |
function toggleMaster(){ | |
$.splitWindow.masterViewVisible = !showMaster; | |
showMaster = !showMaster; | |
} | |
/** | |
* Executes when rotated, resumed, or even when introduced to SplitView or SplitOver Mode | |
*/ | |
$.splitWindow.addEventListener('postlayout',function(e) { | |
if ($.splitWindow.toImage().width <= Alloy.Globals.deviceSmallestMeasurement) { | |
//act as Portrait | |
$.masterCollapseButton.visible = true; | |
$.masterOpenButton.visible = true; | |
} else { | |
//landscape | |
$.masterCollapseButton.visible = false; | |
$.masterOpenButton.visible = false; | |
if (!$.splitWindow.masterViewVisible) { toggleMaster(); } //when rotating to landscape, if master is hidden toggle it to be visible | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment