react-native-gifted-form icon indicating copy to clipboard operation
react-native-gifted-form copied to clipboard

Compatible with react-native-router-flux

Open radiegtya opened this issue 8 years ago • 15 comments

Is this component Compatible with react-native-router-flux?

radiegtya avatar Mar 18 '16 02:03 radiegtya

I didn't try but I guess it should be possible to make it compatible

<GiftedForm
        openModal={(route) => {
           // the trick will be here
        }}
/>

The purpose of openModal prop is to navigate to the modal. The content of the modal is defined by the route object https://github.com/FaridSafi/react-native-gifted-form/blob/master/widgets/ModalWidget.js#L72 which contains renderScene, getTitle, configureScene, renderLeftButton, renderRightButton functions

Maybe #1 can help you

FaridSafi avatar Mar 18 '16 06:03 FaridSafi

how if I just simply install both router? is it just working out of the box without crashing?

radiegtya avatar Mar 18 '16 08:03 radiegtya

It might work

FaridSafi avatar Mar 18 '16 09:03 FaridSafi

Thanks for the response, I'll try it @FaridSafi .

radiegtya avatar Mar 18 '16 09:03 radiegtya

@radiegtya Did you make this works with react-native-router-flux?

minhtc avatar Mar 22 '16 07:03 minhtc

I've managed to get it partially working. I struggled for a while attempting to get the renderRight/Left buttons returned from the ModalWidget working properly with router-flux.

My eventual solution did require me to fork and make this small change (I could not get the displayValue to update properly, this is most likely not in line with the authors intent for navigator usage): https://github.com/deldreth/react-native-gifted-form/blob/master/widgets/ModalWidget.js#L143

The project that this is in reference to is still using react-native-router-flux @ 2.x.

Outside of that...

My modal component... I'm going for simplicity here

import React, {
  Component
} from 'react-native';

export default class FormModal extends Component {
  constructor (props) {
    super(props);
  }

  componentWillUnmount () {
    this.props.updateDisplayValue();
  }

  render () {
    return this.props.renderScene();
  }
}

FormModal.propTypes = {
  renderScene: React.PropTypes.func,
  updateDisplayValue: React.PropTypes.func
};

My GiftedForm and openModal prop: Actions from react-native-router-flux.

<GiftedForm
  openModal={route => {
     Actions.formModal({ ...route, title: route.getTitle() });
  }}>
</GiftedForm>

My Route Configuration:

<Route name='form' title='Installer Signup' component={Form}/>
<Route name='formModal' component={Modal}/>

I could not reliably get right/left navigation bar rendering to work (it may be in relation to the older version of react-native-router-flux this project uses).

deldreth avatar May 03 '16 14:05 deldreth

@deldreth thank's to help, and I found navigation right button render on props.renderRightButton() and props.renderLeftButton() Then we can get inline function onPress()

const btnItem = this.props.renderRightButton()
btnItem.props.onPress()
Actions.pop()

aa900031 avatar May 06 '16 13:05 aa900031

Got this mostly working with react-native-router-flux v3.30, but could use some tips on how to move the confirm button to the right, currently it renders on the left like this:

iphone_6s_-iphone_6s___ios_9_3__13e230

bsy avatar Aug 09 '16 22:08 bsy

ended up adding some styling to the TouchableOpacity in the renderRightButton function in ModalWidget.js to address the positioning

bsy avatar Aug 10 '16 06:08 bsy

@bsy could you say how you did it with react-native-router-flux 3.30?

ramneekhanda avatar Aug 20 '16 04:08 ramneekhanda

@deldreth @aa900031 @bsy it would be of great help if any one of you can share how you got the left/right button to get working and show up at the navbar.

sudugo avatar Sep 28 '16 11:09 sudugo

@ramneekhanda @sudugo and others...

I know it's been several months, but I was able to get modals working using [email protected] + [email protected] and figured I'd share my solution in case you (and anyone else reading this) are [still] interested...

The React component for the modal (I leave the styling up to you)

import React from 'react'
import { ScrollView  } from 'react-native'

export default class FormModalScreen extends React.Component {
  render () {
    return (
      <ScrollView>
        { this.props.renderScene() }
      </ScrollView>
    )
  }
}

The react-native-router-flux configuration

import FormModal from '...'

<Router>
  ...
  <Scene
    key='formModal'
    component={FormModal}
    direction='vertical'
    rightTitle='Save'
  />
  ...
</Router>

The openModal function

import { Actions } from 'react-native-router-flux'

<GiftedForm
  openModal={(route) => {
    Actions.formModal({
      title: route.getTitle(),
      renderScene: route.renderScene,

      /*
        Option 1: If you like the buttons react-native-gifted-form
        gives you, then use this step:
      */
      renderRightButton: route.renderRightButton.bind(route, Actions),
      
      /*
        Option 2: If you prefer your own right button (or text), then
        use this step:
      */
      // onRight: route.onClose.bind(null, null, Actions)
    })
  }}
/>

The reason why you need to use the .bind function passing in Actions is because those methods eventually use that to call navigator.pop() in an onClose function. Without this, the app will crash complaining about how navigator.pop is not a function.

Anyways, hope this helps.


untitled mov

(The screencast animation is a bit strange, but anyways it works)

henrythach avatar Mar 22 '17 17:03 henrythach

@henrythach works perfectly!

ricardokdz avatar May 02 '17 15:05 ricardokdz

Hello, someone help me with the following error I am using the following react-native-gifted-form library, for android. https://github.com/FaridSafi/react-native-gifted-form <GiftedForm.ModalWidget Title = 'Country' DisplayValue = 'country' Image = {require ('../../images/passport.png')} ScrollEnabled = {false}

<GiftedForm.SelectCountryWidget Code = 'alpha2' Name = 'country' Title = 'Country' AutoFocus = {true} /> </GiftedForm.ModalWidget>

dajimene avatar Jun 01 '17 15:06 dajimene

@ramneekhanda @sudugo and others...

I know it's been several months, but I was able to get modals working using [email protected] + [email protected] and figured I'd share my solution in case you (and anyone else reading this) are [still] interested...

The React component for the modal (I leave the styling up to you)

import React from 'react'
import { ScrollView  } from 'react-native'

export default class FormModalScreen extends React.Component {
  render () {
    return (
      <ScrollView>
        { this.props.renderScene() }
      </ScrollView>
    )
  }
}

The react-native-router-flux configuration

import FormModal from '...'

<Router>
  ...
  <Scene
    key='formModal'
    component={FormModal}
    direction='vertical'
    rightTitle='Save'
  />
  ...
</Router>

The openModal function

import { Actions } from 'react-native-router-flux'

<GiftedForm
  openModal={(route) => {
    Actions.formModal({
      title: route.getTitle(),
      renderScene: route.renderScene,

      /*
        Option 1: If you like the buttons react-native-gifted-form
        gives you, then use this step:
      */
      renderRightButton: route.renderRightButton.bind(route, Actions),
      
      /*
        Option 2: If you prefer your own right button (or text), then
        use this step:
      */
      // onRight: route.onClose.bind(null, null, Actions)
    })
  }}
/>

The reason why you need to use the .bind function passing in Actions is because those methods eventually use that to call navigator.pop() in an onClose function. Without this, the app will crash complaining about how navigator.pop is not a function.

Anyways, hope this helps.

untitled mov

(The screencast animation is a bit strange, but anyways it works)

Hello it's not work with last version "react-native": "0.57.7", "react-native-router-flux": "^4.0.6",

it give me this error when i click the modal

_reactNativeRouterFlux.Actions.Modal is not a function

openModal
    ca37f261-62ec-3543-960e-62950ae397f1:167563:13
onPress
    ca37f261-62ec-3543-960e-62950ae397f1:185354:9
onPress/<
    ca37f261-62ec-3543-960e-62950ae397f1:185460:13
setter/</id<
    ca37f261-62ec-3543-960e-62950ae397f1:56417:9
_callTimer
    ca37f261-62ec-3543-960e-62950ae397f1:24014:9
callTimers
    ca37f261-62ec-3543-960e-62950ae397f1:24219:9
__callFunction
    ca37f261-62ec-3543-960e-62950ae397f1:2470:22
callFunctionReturnFlushedQueue/<
    ca37f261-62ec-3543-960e-62950ae397f1:2243:11
__guard
    ca37f261-62ec-3543-960e-62950ae397f1:2424:13
callFunctionReturnFlushedQueue
    ca37f261-62ec-3543-960e-62950ae397f1:2242:9
onmessage
    debuggerWorker.js:72:25

i hope some one help me

Q8hma avatar Dec 16 '18 17:12 Q8hma