react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

BottomNavigation|How to pass props in renderScene?

Open momolly1024 opened this issue 3 years ago • 3 comments

Hi, Dear developers, If I want to add a props to components in BottomNavigation, How can I do?

Some code like this :

const MyComponent = () => {
  const [index, setIndex] = React.useState(0);
  const [routes] = React.useState([
    {key: 'music', title: 'Music', icon: 'gift'},
    {key: 'recents', title: 'Recents', icon: 'history'},
    {key: 'todo', title: 'TodoList', icon: 'github'},
    {key: 'albums', title: 'Albums', icon: 'lock'},
  ]);

  const renderScene = BottomNavigation.SceneMap({
    music: MusicRoute,
    recents: RecentsRoute,
    todo: TodoList,
    albums: AlbumsRoute,
  });

  return (
    <BottomNavigation
      navigationState={{index, routes}}
      onIndexChange={setIndex}
      renderScene={renderScene}
    />
  );
};

I have try to add directly like this, but got an error.

  const renderScene = BottomNavigation.SceneMap({
    music: MusicRoute,
    recents: RecentsRoute,
    **todo: <TodoList test={test}/>,**
    albums: AlbumsRoute,
  });

So I open a issue to ask

Thank you very much!

momolly1024 avatar Aug 23 '22 03:08 momolly1024

Hey! Thanks for opening the issue. The issue doesn't seem to contain a link to a repro (a snack.expo.dev link or link to a GitHub repo under your username).

Can you provide a minimal repro which demonstrates the issue? A repro will help us debug the issue faster. Please try to keep the repro as small as possible and make sure that we can run it without additional setup.

github-actions[bot] avatar Aug 23 '22 03:08 github-actions[bot]

Couldn't find version numbers for the following packages in the issue:

  • react-native
  • react-native-paper
  • react-native-vector-icons

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

github-actions[bot] avatar Aug 23 '22 03:08 github-actions[bot]

Hey @momolly1024, please check the following snack, I hope it will help you.

lukewalczak avatar Aug 23 '22 10:08 lukewalczak

Hey @momolly1024, please check the following snack, I hope it will help you.

Hello @lukewalczak. I'm working with BottomNavigation and I'm facing an issue. Please check this Snack out, it's a fork of your last reply.

Steps:

  • go to Notifications tab;
  • press the "Notification - Add" button;
  • watch the relative counter increase;
  • press the "MyComponent - Add" button;
  • watch the Notification counter set to 0 again.

Is there a way to prevent this behaviour? One solution may be lifting the state of Notification to MyComponent, but I would like to know if there are some alternatives.

MatteoBuffo avatar Nov 25 '22 13:11 MatteoBuffo