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

Can't work with StackNavigator

Open Dannnyho opened this issue 8 years ago • 13 comments

Anyone know how react-native-gifted-form work with { StackNavigator } from 'react-navigation' ??

I tried the ExNaigator but it return evaluating ( this.props.navigator ) Undefined is not an object

Dannnyho avatar May 26 '17 20:05 Dannnyho

I am having the same issue... Is there anyone who is using the ExNavigator with this lib?

prithvibhola avatar Jun 15 '17 14:06 prithvibhola

// in StackScreen

export const StackScreen = StackNavigator({
Modal: {
    screen: StackNavigator({
      defaultModal: { screen: GiftedFormModal }
    }, {
        navigationOptions: {
          header: null,
          gesturesEnabled: false
        },
        cardStyle: {
          shadowOffset: null,
          shadowOpacity: 0,
          shadowRadius: 10,
          backgroundColor: 'red'
        }
      })
  }, ...

// in Widget

...
openModal={router => {
            this.props.navigation.navigate('Modal', {
              renderContent: router.renderScene
            })
          }}
...

// in GiftedFormModal

...
render() {
    const { renderContent } = this.props.navigation.state.params || {}
    return (
      <View style={{ width: '100%', height: '100%' }}>
        {
          renderContent()
        }
      </View>
    )
  }
...

nqhung139 avatar Jun 29 '17 14:06 nqhung139

@nqhung139 can you please post a complete example of your approach? It isn't clear enough for me 😞 First I thought you were suggesting some changes on the lib code base, then I tried to made those changes, but the last part about how to render the content in GiftedFormModal was clear to me. Thanks in advance!

eliasturbay avatar Jul 17 '17 23:07 eliasturbay

@nqhung139 I found the way to make it work. But... it doesn't have the buttons rendered on the NavBar... do you know how to implement that in this approach? 🤔

eliasturbay avatar Jul 18 '17 00:07 eliasturbay

  • In my example router.renderScene use same content of render() scene 'GiftedFormModal'
  • 'GiftedFormModal' defined by 'react-navigation' => if have not NavBar . It is config by 'react-navigation' => do you '...navigationOptions: { header: null ...'? Sorry My English is poor :))

nqhung139 avatar Jul 18 '17 04:07 nqhung139

Thanks @nqhung139 for your quick response. I understand your point, but I changed that part of the configuration to have the nav bar (the header) visible. Take a look at these screenshots: simulator screen shot jul 18 2017 10 09 32 am simulator screen shot jul 18 2017 10 12 41 am

What I am trying to figure out is how to place the same checkmark icon that the library originally use in the right of the Navigator to close the modal widget. Or as a workaround it would be nice to replicate the functionality of closing the modal also when the user choose one of the options in the list. But for now, none of these features are working :(

Any word on this @cooperka ?

eliasturbay avatar Jul 18 '17 13:07 eliasturbay

@eliasturbay I would also like this feature, but I don't have much spare time right now to work on it. If you happen to figure it out, we would all be grateful for a PR 🥇 otherwise I'll try to get to it eventually (no guarantees). Thanks for looking into this.

cooperka avatar Jul 18 '17 14:07 cooperka

@eliasturbay you can try goBack() in 'react-navigation' to close modal , 'GiftedFormManager ' to change and update value with any modal without click value to close. ex : 'DatePickerIOSWidget '

nqhung139 avatar Jul 18 '17 17:07 nqhung139

Thanks @nqhung139 ! That's exactly what I was trying to do (method 'navigation.goBack()'. If it's useful for someone else I will leave it here...

Implementation for openModal function

      <GiftedForm
        formName={'signupForm'}
        openModal={
          (router) => {
            this.props.navigation.navigate('Modal',
              { renderContent: router.renderScene,
                onClose: router.onClose,
                getTitle: router.getTitle
              });
          }
        }

GiftedFormModal.js (this class will receive the methods renderScene and onClose as params thru the navigation object)

import React from 'react';
import PropTypes from 'prop-types';
import { View } from 'react-native';

import { FontAwesome } from '@expo/vector-icons';

class GiftedFormModal extends React.Component {

  static navigationOptions({ navigation }) {
    const { getTitle, onClose } = navigation.state.params || {};

    return {
      headerTitle: getTitle(),
      headerStyle: { backgroundColor: '#F37600' },
      headerTitleStyle: { color: 'white' },
      headerLeft: <FontAwesome
        name="chevron-left"
        color="white"
        size={25}
        style={{ paddingLeft: 10 }}
        onPress={() => {
          navigation.goBack();
        }}
      />,
      headerRight: <FontAwesome
        name="check"
        color="white"
        size={25}
        style={{ paddingRight: 10 }}
        onPress={() => {
          onClose(null, null);
          navigation.goBack();
        }}
      />
    };
  }

  render() {
    const { renderContent } = this.props.navigation.state.params || {};
    return (
      <View style={{ width: '100%', height: '100%' }}>
        {renderContent()}
      </View>
    );
  }
}

GiftedFormModal.propTypes = {
  navigation: PropTypes.shape({
    navigate: PropTypes.func,
    goBack: PropTypes.func,
    state: PropTypes.shape({
      params: PropTypes.object
    })
  })
};

GiftedFormModal.defaultProps = {
  navigation: null
};

export default GiftedFormModal;

Implementation on your React Navigation router (remove node: 'modal' if you don't like it)

const AppNavigator = StackNavigator({
  Main: { screen: MainScreenNavigator },
  Modal: { screen: GiftedFormModal }
}, {
  mode: 'modal',
  headerMode: 'screen'
});

@nqhung139 I still need to figure out the other part to close the modal if you tap on some of the options. I din't fully understand your suggestion about using GiftedFormManager. I'll take a look and give it a try. But if you already know how to do it I will highly appreciate it :)

eliasturbay avatar Jul 18 '17 18:07 eliasturbay

Do you mean create a GiftedFormModal.js for GiftedForm to push the route? i tried to do that but no response when click the ModalWidget? Anyone have a full example of it?

Dannnyho avatar Aug 10 '17 03:08 Dannnyho

@eliasturbay Did u manage to find a solution for "Tap and select option" issue you mentioned above? An example of using the library with React Navigation would be very helpful as Ex-Navigator seems to have been deprecated.

tutak avatar Oct 15 '17 07:10 tutak

Hey @tutak I wasn't able to solve that yet. I would say that it's the only thing I didn't figured out so I'm just using it as it is, it isn't that bad, just one extra step. The code I shared before should be enough for you to use this library with React Navigation

eliasturbay avatar Oct 16 '17 19:10 eliasturbay

Hey @eliasturbay , did you able to implement this tap and select feature on the above modal widgets?

uditchandhoke1912 avatar Jul 11 '18 14:07 uditchandhoke1912