import { registerNativeHandlers } from 'stream-chat-react-native';
registerNativeHandlers({
triggerHaptic: () => null,
});
Native Handlers
Stream Chat for React Native uses a number of features that require packages that run native code.
Stream Chat for React Native also supports Expo, which has it’s own set of native packages.
To reconcile these differences Stream Chat for React Native is made up of two packages, stream-chat-react-native-core
, and either stream-chat-react-native
or stream-chat-expo
.
The non core packages call a function from the core package, registerNativeHandlers
, this gives the core package access to different native functions that perform the same task, but are different between Expo and React Native CLI.
Overriding Handlers
If desired, the native handlers can be overridden using registerNativeHandlers
.
The same function that is called internally to set the handlers can be used to override them.
If the function returns the same type of data as the original function it should seamlessly work with the rest of the SDK.
You should look at the default implementation to ensure any override conforms to the appropriate type definition provided by the SDK.
Example
Haptic feedback is used in the app to indicate certain presses, and within the image viewer to indicate zoom limits are hit. If haptic feedback is not desired in your application you can easily remove it by registering a different handler to the function.
This should be done outside of the component lifecycle to prevent unnecessarily re-registering the same handler repeatedly.
Handlers
There are the handlers registered as they interact with different native API packages depending on if the SDK being used on Expo or React Native CLI.
compressImage
An async
function that compresses an image and returns the local uri
of the compressed image.
React Native CLI | Expo |
---|---|
react-native-image-resizer | expo-image-manipulator |
setClipboardString
An function to copy strings or text in the message.
React Native CLI | Expo |
---|---|
react-native-clipboard | expo-clipboard |
deleteFile
A function that deletes a file at a given local uri
.
React Native CLI | Expo |
---|---|
react-native-fs | expo-file-system |
FlatList
A FlatList component, on Expo the standard React Native component is used, on React Native a modified FlatList better fit for two directional scrolling is used.
React Native CLI | Expo |
---|---|
@stream-io/flat-list-mvcp | react-native |
getLocalAssetUri
A function that gets the local uri
of an image or remote asset.
React Native CLI | Expo |
---|---|
@react-native-community/cameraroll | expo-media-library |
getPhotos
A function that returns photos from the camera roll given an offset of after
and a number to retrieve, first
.
React Native CLI | Expo |
---|---|
@react-native-camera-roll/camera-roll | expo-media-library |
NetInfo
A object containing two keys, addEventListener
and fetch
, which are functions that allow a developer to add listeners to NetInfo
or fetch information from NetInfo
.
React Native CLI | Expo |
---|---|
@react-native-community/netinfo | @react-native-community/netinfo |
pickDocument
A function to open the document picker and return documents picked from it.
React Native CLI | Expo |
---|---|
react-native-document-picker | expo-document-picker |
pickImage
A function to open the native image picker and return images picked from it.
React Native CLI | Expo |
---|---|
react-native-image-picker | expo-image-picker |
saveFile
A function to save a file from a URL to local storage.
React Native CLI | Expo |
---|---|
react-native-fs | expo-file-system |
SDK
String identifying which package, stream-chat-react-native
or stream-chat-expo
, is being used.
React Native CLI | Expo |
---|---|
stream-chat-react-native | stream-chat-expo |
shareImage
A function to provide a given image to the native sharing functionality of the OS.
React Native CLI | Expo |
---|---|
react-native-fs & react-native-share | expo-sharing |
takePhoto
A function that opens the OS specific camera and returns an image when one is taken.
React Native CLI | Expo |
---|---|
react-native-image-crop-picker | expo-image-picker |
triggerHaptic
A function to trigger haptic feedback given the type of haptic force desired.
React Native CLI | Expo |
---|---|
react-native-haptic-feedback | expo-haptics |
Sound
A component that renders the Sound/Audio on the message attachment.
React Native CLI | Expo |
---|---|
react-native-video | expo-av |
Video
A component that renders the Video on the ImageGallery when an video attachment is opened.
React Native CLI | Expo |
---|---|
react-native-video | expo-av |