I have a Kotlin-based native Android chat app that I want to integrate into my React Native project as an android library. The React Native app has a bottom tab bar with four tabs, one for accessing the chat feature. However, when users tap on the chat tab, it opens a new instance of the chat activity, causing the React Native tab bar to disappear and the chat activity to overlay the screen. How can I seamlessly display the native Android chat activity within the React Native app without hiding the tab bar or creating new instances of the app?
Following is my code:
- This is my tabs component using '@react-navigation/bottom-tabs':
const WelcomePageTabs = ({ disabled, onListContainerPress, onSettingsScreenFocused }: IProps) => {
const { t } = useTranslation();
const RecentListScreen = useCallback(() =>
(
<RecentList
disabled = { disabled }
onListContainerPress = { onListContainerPress } />
), []);
const calendarEnabled = useSelector(isCalendarEnabled);
const CalendarListScreen = useCallback(() =>
(
<CalendarList
disabled = { disabled } />
), []);
const SettingsScreen = useCallback(() =>
(
<SettingsNavigationContainer
isInWelcomePage = { true } />
), []);
return (
<WelcomePage.Navigator
backBehavior = { 'none' }
screenOptions = {{
...tabBarOptions,
headerShown: false
}}>
<WelcomePage.Screen
listeners = {{
tabPress: () => {
onSettingsScreenFocused(false);
}
}}
name = { screen.welcome.tabs.recent }
options = {{
...recentListTabBarOptions,
title: t('welcomepage.recentList')
}}>
{ RecentListScreen }
</WelcomePage.Screen>
{
calendarEnabled
&& <WelcomePage.Screen
listeners = {{
tabPress: () => {
onSettingsScreenFocused(false);
}
}}
name = { screen.welcome.tabs.calendar }
options = {{
...calendarListTabBarOptions,
title: t('welcomepage.calendar')
}}>
{ CalendarListScreen }
</WelcomePage.Screen>
}
<WelcomePage.Screen
listeners={{
tabPress: () => {
onSettingsScreenFocused(true);
},
}}
name={screen.settings.main}
options={{
...settingsTabBarOptions,
title: t("welcomepage.settings"),
}}
>
{SettingsScreen}
</WelcomePage.Screen>
<WelcomePage.Screen
listeners={{
tabPress: () => {
onSettingsScreenFocused(true);
},
}}
name={screen.integratedChat}
options={{
...chatTabBarOptions,
title: t("welcomepage.chat"),
}}
>
{IntegratedChat}
</WelcomePage.Screen>
</WelcomePage.Navigator>
);
};
- This is my chat component:
const IntegratedChat = () => {
useEffect(() => {
var chatActivity = NativeModules.ChatActivity;
chatActivity.open();
return () => {
};
}, []);
return (
<View>
</View>
);
};
- This is Chat module:
public class ChatActivityModule extends ReactContextBaseJavaModule {
public ChatActivityModule (ReactApplicationContext reactContext){
super(reactContext);
}
@NonNull
@Override
public String getName() {
return "ChatActivity";
}
@ReactMethod
public void open(){
Intent intent = new Intent(getCurrentActivity(), VectorMainActivity.class);
getCurrentActivity().startActivity(intent);
}
}
Also I have added singletask in main activity in the root of the manifest.
<activity ..
android:launchMode= "singleTask" />