import * as frame from "ui/frame" ; import * as app from 'application' ; import 'nativescript-nbmaterial-layouts/layouts' ; let menu = null ; export function startWithMenu ( page , m ) { menu = m ; app . start ( page ) ; } function getMenuView ( act ) { if ( ! menu ) { throw "MENU PAGE should not be null!" ; } let entry = { moduleName : menu } ; let page = frame [ "resolvePageFromEntry" ] ( entry ) ; let view = page . content ; view . _setupUI ( act ) ; view . onLoaded ( ) ; return view ; } declare var org ; @ JavaProxy ( "com.nmaterial.MainActivity" ) class Activity extends android . app . Activity { private _callbacks : frame . AndroidActivityCallbacks ; public menuView = null ; private callbackFrame ; public onCreate ( savedInstanceState ) { if ( ! this . _callbacks ) { frame . setActivityCallbacks ( this ) ; } this . _callbacks . onCreate ( this , savedInstanceState , super . onCreate ) ; this . callbackFrame = ( arg ) => { const fr = < any > arg . object ; if ( arg . backStackEntry . entry . hideRootMenu ) { fr . hideRootMenu ( ) ; } else { fr . showRootMenu ( ) ; } } ; frame . Frame . onEveryNavigate ( this . callbackFrame ) ; } public setContentView ( param0 ) { if ( typeof param0 == "number" ) { super . setContentView ( param0 ) ; } else { let params = null ; let layout = new android . widget . RelativeLayout ( this ) ; const viewId = android . view . View . generateViewId ( ) ; const menuId = android . view . View . generateViewId ( ) ; params = new android . widget . RelativeLayout . LayoutParams ( android . widget . RelativeLayout . LayoutParams . FILL_PARENT , android . widget . RelativeLayout . LayoutParams . FILL_PARENT ) ; params . addRule ( android . widget . RelativeLayout . ABOVE , menuId ) ; layout . addView ( param0 , params ) ; this . menuView = getMenuView ( this ) ; let mWrap = this . menuView . nativeView ; mWrap . setId ( menuId ) ; params = new android . widget . RelativeLayout . LayoutParams ( android . widget . RelativeLayout . LayoutParams . FILL_PARENT , android . widget . RelativeLayout . LayoutParams . WRAP_CONTENT ) ; params . addRule ( android . widget . RelativeLayout . ALIGN_PARENT_BOTTOM ) ; params . height = < any > this . menuView . height ; layout . addView ( mWrap , params ) ; super . setContentView ( layout ) ; } } public onSaveInstanceState ( outState ) { this . _callbacks . onSaveInstanceState ( this , outState , super . onSaveInstanceState ) ; } public onStart ( ) { this . _callbacks . onStart ( this , super . onStart ) ; } public onStop ( ) { this . _callbacks . onStop ( this , super . onStop ) ; } public onDestroy ( ) { this . menuView = null ; frame . Frame . offEveryNavigate ( this . callbackFrame ) ; this . _callbacks . onDestroy ( this , super . onDestroy ) ; } public onBackPressed ( ) { this . _callbacks . onBackPressed ( this , super . onBackPressed ) ; } public onRequestPermissionsResult ( requestCode , permissions , grantResults ) { this . _callbacks . onRequestPermissionsResult ( this , requestCode , permissions , grantResults , undefined ) ; } public onActivityResult ( requestCode , resultCode , data ) { this . _callbacks . onActivityResult ( this , requestCode , resultCode , data , super . onActivityResult ) ; } } frame . Frame . prototype . showRootMenu = function ( ) { const self = this ; const act = app . android . foregroundActivity || app . android . startActivity ; if ( ! self . isRootMenuVisible ( ) && act . menuView ) { act . menuView . visibility = "visible" ; let an = android ; act . findViewById ( an . R . id . content ) . invalidate ( ) ; } } ; frame . Frame . prototype . hideRootMenu = function ( ) { const self = this ; const act = app . android . foregroundActivity || app . android . startActivity ; if ( this . isRootMenuVisible ( ) ) { act . menuView . visibility = "collapse" ; let an = android ; act . findViewById ( an . R . id . content ) . invalidate ( ) ; } } ; frame . Frame . prototype . isRootMenuVisible = function ( ) { const act = app . android . foregroundActivity || app . android . startActivity ; if ( act . menuView ) { return ! act . menuView . isCollapsed ! ; } return false ; } ;