UNPKG

react-native-unit-components

Version:

Unit React Native components

35 lines (29 loc) 1.01 kB
import { PresentationMode } from '../../types/internal/webComponent.types'; export const webViewId = 'webViewContainer'; export const getHtmlBody = (unitComponent: string, unitComponentProps?: string, presentationMode?: PresentationMode) => { const currentComponent = `<${unitComponent} ${unitComponentProps || ''} }> </${unitComponent}>`; switch (presentationMode) { case PresentationMode.CoverInjectedHeight: return getCoverInjectedHeightBodyScript(currentComponent); case PresentationMode.Inherit: return getInheritParentSizeScript(currentComponent); default: return currentComponent; } }; const getCoverInjectedHeightBodyScript = (currentUnitScript: string) => { return ` <div id=${webViewId}> <div style="height: 100%; display: block;"> ${currentUnitScript} </div> </div> `; }; const getInheritParentSizeScript = (currentUnitScript: string) => { return ` <div style="height: 100vh"> ${currentUnitScript} </div> `; };