React Native
The bubble in a React Native app, with Expo (managed or bare) or bare React Native.
@mawgood/chat-react-native draws the chat with React Native components (no WebView) on iOS and
Android. It needs react 18.2 or later and react-native 0.74 or later.
Allow your app
In your Mawgood › Overview and channels › Website & app chat, add your app to the site key's
Allowed sites and apps: the iOS bundle ID (Xcode › the target › Bundle Identifier) and the
Android package name (applicationId in build.gradle), both like com.example.app. A call
from an app that isn't listed is refused with origin_not_allowed.
Install
Managed or bare Expo apps:
npm install @mawgood/chat-react-native
npx expo install expo-secure-store @react-native-async-storage/async-storage expo-application \
expo-image-picker expo-document-picker expo-audio expo-haptics react-native-safe-area-contextAdd the config plugin. It adds the microphone and photo permission strings on iOS and
RECORD_AUDIO on Android, and the secure store's plugin keeps the device id out of Android backups:
{
"expo": {
"plugins": [
"@mawgood/chat-react-native",
["expo-secure-store", { "configureAndroidBackup": true }]
]
}
}Add the provider
import { MawgoodChatProvider, MawgoodLauncher } from '@mawgood/chat-react-native';
import { expoAdapters } from '@mawgood/chat-react-native/expo';
const adapters = expoAdapters();
export default function App() {
return (
<MawgoodChatProvider siteKey="mwg_pk_live_…" mawgoodId="mw_ag_…" adapters={adapters}>
<YourApp />
<MawgoodLauncher />
</MawgoodChatProvider>
);
}Anywhere below the provider, useMawgoodChat() opens the chat and tells the Mawgood where the
customer is:
const chat = useMawgoodChat();
chat.open();
chat.setPage('product'); // the screen name
chat.setAttributes({ cart: 450 });The chat opens the way the look's window mode says: full screen, a bottom sheet, or a floating
panel (sideSheet is web only and opens floating). To put it inside a screen of your own, use
<MawgoodChatView visible={isFocused} />. If the screen is itself a native modal
(presentation: 'modal'), embed MawgoodChatView there: on iOS a React Native Modal over a
native modal can open behind it.
Provider props
| Prop | What it does |
|---|---|
siteKey, mawgoodId | Required. |
environment | production (default) or staging. |
baseUrl, realtimeUrl | Another API or realtime host (local development). |
locale | ar, en-US…; default the device's. |
look | Your in-code look (Customization). |
identity | A signed customer; null after one was set logs them out. |
adapters | Storage, the app ID, pickers, audio, haptics, safe areas (expoAdapters()). |
appId | Overrides the bundle ID / package name the adapters read. |
renderHeader, renderMessage, renderEmpty | Your own header, message renderer and empty state. |
onOpen, onClose, onMessage, onUnreadChange, onHandoff, onError | Events. |
Adapters
expoAdapters() gives every adapter. /expo/storage, /expo/app, /expo/pickers, /expo/audio,
/expo/haptics and /safe-area give one each, so a bare app imports only those whose libraries it
has. Any can be yours (MawgoodAdapters): storage (the device id and the offline outbox),
firstRun (a marker the OS wipes on uninstall, so the iOS Keychain doesn't bring back an old
visitor), appId, pickImages, pickFiles, useRecorder, usePlayer, playSound, haptic,
useSafeAreaInsets and SafeAreaProvider. Without one, that feature is off and the chat still
works.
While it records or plays a voice note the chat switches the audio mode, then puts yours back.
If your app sets its own audio mode, tell the SDK with setAppAudioMode({ … }) from /expo/audio.
Push notifications
Push for a closed app comes later: registerPushToken() does nothing yet. Meanwhile, use
onUnreadChange with your own push system.