Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tear down views after a modal is closed (#9801)
- Loading branch information
1 parent
c876d16
commit b38337e
Showing
5 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,46 @@ | ||
import { Page, ShownModallyData, Observable } from '@nativescript/core'; | ||
import { Page, ShownModallyData, Observable, LoadEventData } from '@nativescript/core'; | ||
|
||
let page: Page; | ||
let closeCallback: Function; | ||
export function onShownModally(args: ShownModallyData) { | ||
page = <Page>args.object; | ||
page.bindingContext = new SampleModal(); | ||
console.log('page shown modally'); | ||
|
||
closeCallback = args.closeCallback; | ||
|
||
if (args.context) { | ||
args.context.shownModally = true; | ||
} | ||
} | ||
|
||
export function onLoaded(args: LoadEventData) { | ||
console.log('page loaded'); | ||
|
||
page = args.object as Page; | ||
page.bindingContext = new SampleModal(); | ||
|
||
const disposePage = page.disposeNativeView.bind(page); | ||
page.disposeNativeView = () => { | ||
console.log('-'.repeat(100)); | ||
console.log(' [!!] Disposing modal page...'); | ||
console.log('-'.repeat(100)); | ||
|
||
disposePage(); | ||
}; | ||
} | ||
|
||
export class SampleModal extends Observable { | ||
close() { | ||
// TODO: a11y | ||
// if (global.isIOS) { | ||
// (<UIViewController>page.ios).view.accessibilityPerformEscape(); | ||
// } | ||
closeCallback(); | ||
if (typeof closeCallback === 'function') { | ||
closeCallback('data from modal'); | ||
// reset callback... | ||
closeCallback = undefined; | ||
} else { | ||
// fallback to regular nav back... | ||
page.frame.goBack(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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