UNPKG

react-native-unit-components

Version:

Unit React Native components

55 lines 2.03 kB
import React, { useState } from 'react'; import { WebComponent } from '../../webComponent/WebComponent'; import { PresentationMode, WebComponentType } from '../../types/internal/webComponent.types'; import { getProgramDetailsParams } from './UNProgramDetailsComponent.utils'; import { withReduxStore } from '../../helpers/store/helpers'; import { RESPONSE_KEYS } from '../../messages/webMessages/onLoadMessage'; import { UnitComponentsMessage } from '../../messages/webMessages/unitComponentsMessages'; import { PageMessage } from '../../messages/webMessages/pageMessage'; import { UNBaseView } from '../../nativeComponents/UNBaseView'; const UNProgramDetailsComponent = props => { const [height, setHeight] = useState(0); const handleUnitOnLoad = response => { console.log('handleUnitOnLoad', response); if (!props.onLoad) { return; } if (RESPONSE_KEYS.errors in response) { props.onLoad(response); return; } if (RESPONSE_KEYS.account in response) { props.onLoad(response[RESPONSE_KEYS.account]); return; } console.error('On Load Error: unexpected response type.'); return; }; const handleMessage = message => { switch (message.type) { case UnitComponentsMessage.UNIT_ON_LOAD: handleUnitOnLoad(message.details); break; case PageMessage.PAGE_HEIGHT: setHeight(message.details.height); break; } }; return /*#__PURE__*/React.createElement(UNBaseView, { style: { height, width: '100%' }, onLoadError: handleUnitOnLoad, fallback: /*#__PURE__*/React.createElement(React.Fragment, null) }, /*#__PURE__*/React.createElement(WebComponent, { type: WebComponentType.programDetails, presentationMode: PresentationMode.Default, params: getProgramDetailsParams(props), theme: props.theme, language: props.language, onMessage: handleMessage })); }; export default withReduxStore(UNProgramDetailsComponent); //# sourceMappingURL=UNProgramDetailsComponent.js.map