0

I am trying to create such a functionality, where I can choose multiple options on screen and process options data on tab press. Data which is stored in screen should be sent on tab press, how can I handle it?

<Tab.Navigator>
  <Tab.Screen name="SendMail" component={OptionsScreen} 
listeners={{
      onPress : ()=> {
                    //call my function from component here
                                 }
                   }}
 />
  <Tab.Screen name="AddToCalendar" component={CalendarScreen} />
  <Tab.Screen name="Info" component={InfoScreen} />
</Tab.Navigator>

function OptionsScreen({navigation}) {
  //data which is needed to be sent on tab press is stored in this component
  const [selectedIds, setSelectedIds] = useState([]);



  function sendEmailWithSelectedIds() {
    //function which is need to be called on tab press
    sendEmail(selectedIds);
  }

  function handleSelect(id) {
    setSelectedIds([...selectedIds, id]);
  }
}

screen example

Julia
  • 1
  • 1

1 Answers1

0

there's useIsFocused hook in react-navigation. it detects if current screen is focused or not. https://reactnavigation.org/docs/use-is-focused

Erdenezaya
  • 141
  • 4