From c2a1173bd0c763958810fbfdf64537b7bd3a7924 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 27 May 2020 11:46:26 -0300 Subject: [PATCH] block modal --- app/views/ModalBlockView.js | 75 ++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/app/views/ModalBlockView.js b/app/views/ModalBlockView.js index 7bb91ca20..57b415fdc 100644 --- a/app/views/ModalBlockView.js +++ b/app/views/ModalBlockView.js @@ -6,7 +6,6 @@ import { connect } from 'react-redux'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import { withTheme } from '../theme'; -import { themedHeader } from '../utils/navigation'; import EventEmitter from '../utils/events'; import { themes } from '../constants/colors'; import { CustomHeaderButtons, Item } from '../containers/HeaderButton'; @@ -58,35 +57,11 @@ const reduceState = (obj, el) => (Array.isArray(el[0]) ? { ...obj, ...Object.fro class ModalBlockView extends React.Component { static navigationOptions = ({ route }) => { - // const { theme, closeModal } = screenProps; const data = route.params?.data; - // const cancel = route.params?.cancel ?? (() => {}); - const submitting = route.params?.submitting ?? false; const { view } = data; - const { title, submit, close } = view; + const { title } = view; return { - title: textParser([title]), - headerLeft: close ? () => ( - - cancel({ closeModal }))} - testID='close-modal-uikit' - /> - - ) : null, - headerRight: submit ? ( - - {}))} - testID='submit-modal-uikit' - /> - - ) : null + title: textParser([title]) }; } @@ -110,14 +85,12 @@ class ModalBlockView extends React.Component { data, loading: false }; + this.setHeader(); } componentDidMount() { const { data } = this.state; - const { navigation } = this.props; const { viewId } = data; - navigation.setParams({ submit: this.submit, cancel: this.cancel }); - EventEmitter.addEventListener(viewId, this.handleUpdate); } @@ -147,14 +120,43 @@ class ModalBlockView extends React.Component { EventEmitter.removeListener(viewId, this.handleUpdate); } - handleUpdate = ({ type, ...data }) => { + setHeader = () => { + const { data } = this.state; const { navigation } = this.props; + const { view } = data; + const { title, close, submit } = view; + navigation.setOptions({ + title: textParser([title]), + headerLeft: close ? () => ( + + + + ) : null, + headerRight: submit ? () => ( + + + + ) : null + }); + } + + handleUpdate = ({ type, ...data }) => { if ([MODAL_ACTIONS.ERRORS].includes(type)) { const { errors } = data; this.setState({ errors }); } else { this.setState({ data }); - navigation.setParams({ data }); + this.setHeader(); } }; @@ -187,8 +189,11 @@ class ModalBlockView extends React.Component { submit = async() => { const { data } = this.state; - const { navigation } = this.props; - navigation.setParams({ submitting: true }); + if (this.submitting) { + return; + } + + this.submitting = true; const { appId, viewId } = data; this.setState({ loading: true }); @@ -207,7 +212,7 @@ class ModalBlockView extends React.Component { // do nothing } - navigation.setParams({ submitting: false }); + this.submitting = false; this.setState({ loading: false }); };