Skip to content

Commit 9e89a66

Browse files
authored
fix: expose default native handlers (#3704)
## 🎯 Goal This PR addresses [this GH issue](#3379). While exposing a prop might be slightly more convenient, our native handlers have a ton of arguments we don't want to expose every single one of them separately as it will cause an argument storm. Instead, we expose the default native handlers and allow integrators to use them as they see fit. For example, they could invoke them with different properties, make them conditionally depend on configuration and similar. It would also make it easier to conditionally override the handlers in certain scenarios. Runtime passing of different arguments should still be done on the callsites themselves, this approach is more of a global switch to something else if necessary. ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent 448ebd8 commit 9e89a66

4 files changed

Lines changed: 76 additions & 4 deletions

File tree

package/expo-package/src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import {
2424
Video,
2525
} from './optionalDependencies';
2626

27-
registerNativeHandlers({
27+
/**
28+
* The default native handlers this package registers with the core SDK.
29+
*/
30+
export const defaultNativeHandlers = {
2831
Audio,
2932
compressImage,
3033
deleteFile,
@@ -39,13 +42,17 @@ registerNativeHandlers({
3942
pickDocument,
4043
pickImage,
4144
saveFile,
42-
SDK: 'stream-chat-expo',
4345
setClipboardString,
4446
shareImage,
4547
Sound,
4648
takePhoto,
4749
triggerHaptic,
4850
Video,
51+
};
52+
53+
registerNativeHandlers({
54+
...defaultNativeHandlers,
55+
SDK: 'stream-chat-expo',
4956
});
5057

5158
export * from 'stream-chat-react-native-core';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1+
import { registerNativeHandlers } from 'stream-chat-react-native-core';
2+
13
export * from 'stream-chat-react-native-core';
4+
5+
/**
6+
* The default native handlers this package registers with the core SDK.
7+
*
8+
* Exposed so integrators can compose or wrap a single handler (for example to
9+
* force `takePhoto` to capture images only) without reimplementing it or
10+
* reaching into internal module paths. Register your override *after* importing
11+
* this package so it takes precedence.
12+
*
13+
* Example:
14+
*
15+
* ```ts
16+
* import { registerNativeHandlers, defaultNativeHandlers } from 'stream-chat-expo';
17+
*
18+
* const localTakePhoto = defaultNativeHandlers.takePhoto;
19+
*
20+
* registerNativeHandlers({
21+
* takePhoto: localTakePhoto
22+
* ? (options) => {
23+
* console.log('[#3379 demo] wrapped takePhoto — forcing mediaType "image"', options);
24+
* return localTakePhoto({ ...options, mediaType: 'image' });
25+
* }
26+
* : undefined,
27+
* });
28+
* ```
29+
*/
30+
export declare const defaultNativeHandlers: Parameters<typeof registerNativeHandlers>[0];

package/native-package/src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
Video,
2626
} from './optionalDependencies';
2727

28-
registerNativeHandlers({
28+
/**
29+
* The default native handlers this package registers with the core SDK.
30+
*/
31+
export const defaultNativeHandlers = {
2932
Audio,
3033
compressImage,
3134
deleteFile,
@@ -40,13 +43,17 @@ registerNativeHandlers({
4043
pickDocument,
4144
pickImage,
4245
saveFile,
43-
SDK: 'stream-chat-react-native',
4446
setClipboardString,
4547
shareImage,
4648
Sound,
4749
takePhoto,
4850
triggerHaptic,
4951
Video,
52+
};
53+
54+
registerNativeHandlers({
55+
...defaultNativeHandlers,
56+
SDK: 'stream-chat-react-native',
5057
});
5158

5259
if (Platform.OS === 'android') {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1+
import { registerNativeHandlers } from 'stream-chat-react-native-core';
2+
13
export * from 'stream-chat-react-native-core';
4+
5+
/**
6+
* The default native handlers this package registers with the core SDK.
7+
*
8+
* Exposed so integrators can compose or wrap a single handler (for example to
9+
* force `takePhoto` to capture images only) without reimplementing it or
10+
* reaching into internal module paths. Register your override *after* importing
11+
* this package so it takes precedence.
12+
*
13+
* Example:
14+
*
15+
* ```ts
16+
* import { registerNativeHandlers, defaultNativeHandlers } from 'stream-chat-expo';
17+
*
18+
* const localTakePhoto = defaultNativeHandlers.takePhoto;
19+
*
20+
* registerNativeHandlers({
21+
* takePhoto: localTakePhoto
22+
* ? (options) => {
23+
* console.log('[#3379 demo] wrapped takePhoto — forcing mediaType "image"', options);
24+
* return localTakePhoto({ ...options, mediaType: 'image' });
25+
* }
26+
* : undefined,
27+
* });
28+
* ```
29+
*/
30+
export declare const defaultNativeHandlers: Parameters<typeof registerNativeHandlers>[0];

0 commit comments

Comments
 (0)