mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
chore(packages): move the packages to root
This commit is contained in:
44
react/src/react-framework-delegate.ts
Normal file
44
react/src/react-framework-delegate.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { FrameworkDelegate } from '@ionic/core';
|
||||
import { isElementModal, isElementNav } from './utils/helpers';
|
||||
|
||||
export function attachViewToDom(parentElement: HTMLElement, reactComponent: any, propsOrData: any, classesToAdd: string[]) {
|
||||
const wrappingDiv = shouldWrapInIonPage(parentElement) ? document.createElement('ion-page') : document.createElement('div');
|
||||
if (classesToAdd) {
|
||||
for (const clazz of classesToAdd) {
|
||||
wrappingDiv.classList.add(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
parentElement.appendChild(wrappingDiv);
|
||||
|
||||
// mount the React component
|
||||
const reactElement = React.createElement(reactComponent, propsOrData);
|
||||
const mountedComponentInstance = ReactDOM.render(reactElement, wrappingDiv);
|
||||
|
||||
return Promise.resolve({
|
||||
element: wrappingDiv,
|
||||
reactElement: reactElement,
|
||||
instance: mountedComponentInstance
|
||||
});
|
||||
}
|
||||
|
||||
export function removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement): Promise<any> {
|
||||
ReactDOM.unmountComponentAtNode(childElement);
|
||||
parentElement.removeChild(childElement);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const Delegate: FrameworkDelegate = {
|
||||
attachViewToDom: attachViewToDom,
|
||||
removeViewFromDom: removeViewFromDom,
|
||||
};
|
||||
|
||||
export { Delegate }
|
||||
|
||||
|
||||
export function shouldWrapInIonPage(element: HTMLElement) {
|
||||
return isElementModal(element) || isElementNav(element);
|
||||
}
|
Reference in New Issue
Block a user