react-native-unit-components
Version:
Unit React Native components
64 lines • 2.33 kB
JavaScript
import React, { useState } from 'react';
import { withReduxStore } from '../../helpers/store/helpers';
import { PageMessage } from '../../messages/webMessages/pageMessage';
import { UnitComponentsMessage } from '../../messages/webMessages/unitComponentsMessages';
import { UNBaseView } from '../../nativeComponents/UNBaseView';
import { RESPONSE_KEYS } from '../../messages/webMessages/onLoadMessage';
import { WebComponent } from '../../webComponent/WebComponent';
import { PresentationMode, WebComponentType } from '../../types/internal/webComponent.types';
import { getCardActionParams, getCardActionScript } from './UNCardActionComponent.utils';
import { Dimensions } from 'react-native';
const DEFAULT_HEIGHT = Dimensions.get('window').height * 0.5;
const UNCardActionComponent = props => {
const [defaultHeight, setDefaultHeight] = useState();
const handleUnitOnLoad = response => {
if (!props.onLoad) {
return;
}
if (RESPONSE_KEYS.errors in response) {
props.onLoad(response);
return;
}
props.onLoad({
data: undefined
});
};
const handleMessage = message => {
if (!message) return;
switch (message.type) {
case PageMessage.PAGE_HEIGHT:
{
const currentHeight = message.details.height;
currentHeight === 0 && setDefaultHeight(DEFAULT_HEIGHT);
break;
}
case UnitComponentsMessage.UNIT_ON_LOAD:
handleUnitOnLoad(message.details);
break;
case UnitComponentsMessage.UNIT_REQUEST_CLOSE_FLOW:
props.onCloseFlow && props.onCloseFlow();
break;
}
};
const style = defaultHeight ? {
height: defaultHeight
} : {
flex: 1
};
return /*#__PURE__*/React.createElement(UNBaseView, {
style: style,
onLoadError: handleUnitOnLoad,
fallback: /*#__PURE__*/React.createElement(React.Fragment, null)
}, /*#__PURE__*/React.createElement(WebComponent, {
type: WebComponentType.cardAction,
presentationMode: PresentationMode.Inherit,
params: getCardActionParams(props),
theme: props.theme,
language: props.language,
script: getCardActionScript(),
onMessage: message => handleMessage(message),
isScrollable: true
}));
};
export default withReduxStore(UNCardActionComponent);
//# sourceMappingURL=UNCardActionComponent.js.map