refactor(framework-delegate): conditionally use for host element for modal and nav

This commit is contained in:
Dan Bucholtz
2018-01-03 16:36:18 -06:00
parent 3604adf841
commit 365b80bedb
3 changed files with 38 additions and 29 deletions

View File

@ -4,7 +4,9 @@ import ReactDOM from 'react-dom';
import { FrameworkDelegate } from '@ionic/core';
export function attachViewToDom(parentElement: HTMLElement, reactComponent: any, propsOrData: any, classesToAdd: string[]) {
const wrappingDiv = document.createElement('div');
console.log('parentElement: ', parentElement);
console.log('reactComponent: ', reactComponent);
const wrappingDiv = shouldWrapInIonPage(parentElement) ? document.createElement('ion-page') : document.createElement('div');
if (classesToAdd) {
for (const clazz of classesToAdd) {
wrappingDiv.classList.add(clazz);
@ -22,7 +24,6 @@ export function attachViewToDom(parentElement: HTMLElement, reactComponent: any,
reactElement: reactElement,
instance: mountedComponentInstance
});
}
export function removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement): Promise<any> {
@ -36,4 +37,12 @@ const Delegate: FrameworkDelegate = {
removeViewFromDom: removeViewFromDom,
};
export { Delegate }
export { Delegate }
export function shouldWrapInIonPage(element: HTMLElement) {
if (element.tagName.toUpperCase() === 'ION-NAV' || element.classList.contains('modal-wrapper')) {
return true;
}
return false;
}