stream-chat-react-native-core 4.0.0-beta.6 → 4.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/commonjs/components/Chat/Chat.js +8 -4
- package/lib/commonjs/components/Chat/Chat.js.map +1 -1
- package/lib/commonjs/init.js +13 -0
- package/lib/commonjs/init.js.map +1 -0
- package/lib/commonjs/utils/getResizedImageUrl.js +8 -5
- package/lib/commonjs/utils/getResizedImageUrl.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Chat/Chat.js +8 -4
- package/lib/module/components/Chat/Chat.js.map +1 -1
- package/lib/module/init.js +13 -0
- package/lib/module/init.js.map +1 -0
- package/lib/module/utils/getResizedImageUrl.js +8 -5
- package/lib/module/utils/getResizedImageUrl.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/init.d.ts +2 -0
- package/lib/typescript/utils/getResizedImageUrl.d.ts +2 -1
- package/package.json +2 -4
- package/src/components/Attachment/__tests__/buildGallery.test.js +4 -4
- package/src/components/Chat/Chat.tsx +3 -0
- package/src/init.ts +5 -0
- package/src/utils/__tests__/getResizedImageUrl.test.js +56 -0
- package/src/utils/getResizedImageUrl.ts +15 -13
- package/src/version.json +1 -1
- package/lib/commonjs/styleguideComponents/ArgumentsRenderer.js +0 -100
- package/lib/commonjs/styleguideComponents/ArgumentsRenderer.js.map +0 -1
- package/lib/commonjs/styleguideComponents/BottomSheet.js +0 -25
- package/lib/commonjs/styleguideComponents/BottomSheet.js.map +0 -1
- package/lib/commonjs/styleguideComponents/JsDoc.js +0 -87
- package/lib/commonjs/styleguideComponents/JsDoc.js.map +0 -1
- package/lib/commonjs/styleguideComponents/Markdown.js +0 -12
- package/lib/commonjs/styleguideComponents/Markdown.js.map +0 -1
- package/lib/commonjs/styleguideComponents/PathlineRenderer.js +0 -92
- package/lib/commonjs/styleguideComponents/PathlineRenderer.js.map +0 -1
- package/lib/commonjs/styleguideComponents/PropsRenderer.js +0 -267
- package/lib/commonjs/styleguideComponents/PropsRenderer.js.map +0 -1
- package/lib/commonjs/styleguideComponents/Reanimated.js +0 -2
- package/lib/commonjs/styleguideComponents/Reanimated.js.map +0 -1
- package/lib/commonjs/styleguideComponents/Wrapper.js +0 -29
- package/lib/commonjs/styleguideComponents/Wrapper.js.map +0 -1
- package/lib/commonjs/styleguideComponents/register-react-native-web.js +0 -44
- package/lib/commonjs/styleguideComponents/register-react-native-web.js.map +0 -1
- package/lib/commonjs/styleguideComponents/resolveAssetSource.js +0 -11
- package/lib/commonjs/styleguideComponents/resolveAssetSource.js.map +0 -1
- package/lib/module/styleguideComponents/ArgumentsRenderer.js +0 -100
- package/lib/module/styleguideComponents/ArgumentsRenderer.js.map +0 -1
- package/lib/module/styleguideComponents/BottomSheet.js +0 -25
- package/lib/module/styleguideComponents/BottomSheet.js.map +0 -1
- package/lib/module/styleguideComponents/JsDoc.js +0 -87
- package/lib/module/styleguideComponents/JsDoc.js.map +0 -1
- package/lib/module/styleguideComponents/Markdown.js +0 -12
- package/lib/module/styleguideComponents/Markdown.js.map +0 -1
- package/lib/module/styleguideComponents/PathlineRenderer.js +0 -92
- package/lib/module/styleguideComponents/PathlineRenderer.js.map +0 -1
- package/lib/module/styleguideComponents/PropsRenderer.js +0 -267
- package/lib/module/styleguideComponents/PropsRenderer.js.map +0 -1
- package/lib/module/styleguideComponents/Reanimated.js +0 -2
- package/lib/module/styleguideComponents/Reanimated.js.map +0 -1
- package/lib/module/styleguideComponents/Wrapper.js +0 -29
- package/lib/module/styleguideComponents/Wrapper.js.map +0 -1
- package/lib/module/styleguideComponents/register-react-native-web.js +0 -44
- package/lib/module/styleguideComponents/register-react-native-web.js.map +0 -1
- package/lib/module/styleguideComponents/resolveAssetSource.js +0 -11
- package/lib/module/styleguideComponents/resolveAssetSource.js.map +0 -1
- package/src/styleguideComponents/ArgumentsRenderer.tsx +0 -60
- package/src/styleguideComponents/BottomSheet.tsx +0 -3
- package/src/styleguideComponents/JsDoc.tsx +0 -45
- package/src/styleguideComponents/Markdown.tsx +0 -1
- package/src/styleguideComponents/PathlineRenderer.tsx +0 -45
- package/src/styleguideComponents/PropsRenderer.tsx +0 -141
- package/src/styleguideComponents/Reanimated.tsx +0 -0
- package/src/styleguideComponents/Wrapper.tsx +0 -7
- package/src/styleguideComponents/register-react-native-web.js +0 -13
- package/src/styleguideComponents/resolveAssetSource.js +0 -2
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ This repo includes 4 example apps. One made with Expo, one Native JavaScript cod
|
|
|
46
46
|
|
|
47
47
|
- [Expo example](./examples/ExpoMessaging)
|
|
48
48
|
- [Native example](./examples/NativeMessaging)
|
|
49
|
-
- [Typescript example](./examples/
|
|
49
|
+
- [Typescript example](./examples/TypeScriptMessaging)
|
|
50
50
|
- [Fully featured messaging application](./examples/SampleApp)
|
|
51
51
|
|
|
52
52
|
Besides, our team maintains a dedicated repository for fully-fledged sample applications and demos at [GetStream/react-native-samples](https://github.com/GetStream/react-native-samples). Please consider checking following sample applications:
|
|
@@ -33,6 +33,8 @@ var _TranslationContext = require("../../contexts/translationContext/Translation
|
|
|
33
33
|
|
|
34
34
|
var _useStreami18n = require("../../hooks/useStreami18n");
|
|
35
35
|
|
|
36
|
+
var _init = _interopRequireDefault(require("../../init"));
|
|
37
|
+
|
|
36
38
|
var _native = require("../../native");
|
|
37
39
|
|
|
38
40
|
var _version = require("../../version.json");
|
|
@@ -44,6 +46,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
44
46
|
|
|
45
47
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
48
|
|
|
49
|
+
(0, _init["default"])();
|
|
50
|
+
|
|
47
51
|
var ChatWithContext = function ChatWithContext(props) {
|
|
48
52
|
var children = props.children,
|
|
49
53
|
client = props.client,
|
|
@@ -104,7 +108,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
104
108
|
__self: _this,
|
|
105
109
|
__source: {
|
|
106
110
|
fileName: _jsxFileName,
|
|
107
|
-
lineNumber:
|
|
111
|
+
lineNumber: 176,
|
|
108
112
|
columnNumber: 5
|
|
109
113
|
}
|
|
110
114
|
}, _react["default"].createElement(_TranslationContext.TranslationProvider, {
|
|
@@ -112,7 +116,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
112
116
|
__self: _this,
|
|
113
117
|
__source: {
|
|
114
118
|
fileName: _jsxFileName,
|
|
115
|
-
lineNumber:
|
|
119
|
+
lineNumber: 177,
|
|
116
120
|
columnNumber: 7
|
|
117
121
|
}
|
|
118
122
|
}, _react["default"].createElement(_ThemeContext.ThemeProvider, {
|
|
@@ -120,7 +124,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
120
124
|
__self: _this,
|
|
121
125
|
__source: {
|
|
122
126
|
fileName: _jsxFileName,
|
|
123
|
-
lineNumber:
|
|
127
|
+
lineNumber: 178,
|
|
124
128
|
columnNumber: 9
|
|
125
129
|
}
|
|
126
130
|
}, children)));
|
|
@@ -136,7 +140,7 @@ var Chat = function Chat(props) {
|
|
|
136
140
|
__self: _this,
|
|
137
141
|
__source: {
|
|
138
142
|
fileName: _jsxFileName,
|
|
139
|
-
lineNumber:
|
|
143
|
+
lineNumber: 212,
|
|
140
144
|
columnNumber: 10
|
|
141
145
|
}
|
|
142
146
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Chat.tsx"],"names":["ChatWithContext","props","children","client","closeConnectionOnBackground","i18nInstance","style","channel","setChannel","t","key","tDateTimeParser","input","translators","setTranslators","loadingTranslators","connectionRecovering","isOnline","mutedUsers","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","setActiveChannel","newChannel","chatContext","Chat"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;;AAEA;;AAGA;;;;;;;;;AA+FA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAGtBC,KAHsB,EAInB;AACH,MAAQC,QAAR,GAAsFD,KAAtF,CAAQC,QAAR;AAAA,MAAkBC,MAAlB,GAAsFF,KAAtF,CAAkBE,MAAlB;AAAA,8BAAsFF,KAAtF,CAA0BG,2BAA1B;AAAA,MAA0BA,2BAA1B,sCAAwD,IAAxD;AAAA,MAA8DC,YAA9D,GAAsFJ,KAAtF,CAA8DI,YAA9D;AAAA,MAA4EC,KAA5E,GAAsFL,KAAtF,CAA4EK,KAA5E;;AAEA,kBAA8B,sBAA9B;AAAA;AAAA,MAAOC,OAAP;AAAA,MAAgBC,UAAhB;;AACA,mBAAsC,qBAAkC;AACtEC,IAAAA,CAAC,EAAE,WAACC,GAAD;AAAA,aAAiBA,GAAjB;AAAA,KADmE;AAEtEC,IAAAA,eAAe,EAAE,yBAACC,KAAD;AAAA,aAAoC,uBAAMA,KAAN,CAApC;AAAA;AAFqD,GAAlC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AAQA,MAAMC,kBAAkB,GAAG,kCAAc;AAAEV,IAAAA,YAAY,EAAZA,YAAF;AAAgBS,IAAAA,cAAc,EAAdA;AAAhB,GAAd,CAA3B;;AAKA,qBAA2C,+BACzCX,MADyC,EAEzCC,2BAFyC,CAA3C;AAAA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CAAC,eAAD;AAAuBA,IAAAA,KAAK,EAALA;AAAvB,KAAoCL,KAApC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAP;AACD,CARM","sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel } from 'stream-chat';\n\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n TranslationContextValue,\n TranslationProvider,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\n\nimport { SDK } from '../../native';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/master/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n};\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { children, client, closeConnectionOnBackground = true, i18nInstance, style } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslationContextValue>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n /**\n * Setup muted user listener\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n useEffect(() => {\n if (client.setUserAgent) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n }\n }, []);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n const chatContext = useCreateChatContext({\n channel,\n client,\n connectionRecovering,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider value={translators}>\n <ThemeProvider style={style}>{children}</ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["Chat.tsx"],"names":["ChatWithContext","props","children","client","closeConnectionOnBackground","i18nInstance","style","channel","setChannel","t","key","tDateTimeParser","input","translators","setTranslators","loadingTranslators","connectionRecovering","isOnline","mutedUsers","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","setActiveChannel","newChannel","chatContext","Chat"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;;AACA;;AAEA;;AAGA;;;;;;;;;AAEA;;AA+FA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAGtBC,KAHsB,EAInB;AACH,MAAQC,QAAR,GAAsFD,KAAtF,CAAQC,QAAR;AAAA,MAAkBC,MAAlB,GAAsFF,KAAtF,CAAkBE,MAAlB;AAAA,8BAAsFF,KAAtF,CAA0BG,2BAA1B;AAAA,MAA0BA,2BAA1B,sCAAwD,IAAxD;AAAA,MAA8DC,YAA9D,GAAsFJ,KAAtF,CAA8DI,YAA9D;AAAA,MAA4EC,KAA5E,GAAsFL,KAAtF,CAA4EK,KAA5E;;AAEA,kBAA8B,sBAA9B;AAAA;AAAA,MAAOC,OAAP;AAAA,MAAgBC,UAAhB;;AACA,mBAAsC,qBAAkC;AACtEC,IAAAA,CAAC,EAAE,WAACC,GAAD;AAAA,aAAiBA,GAAjB;AAAA,KADmE;AAEtEC,IAAAA,eAAe,EAAE,yBAACC,KAAD;AAAA,aAAoC,uBAAMA,KAAN,CAApC;AAAA;AAFqD,GAAlC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AAQA,MAAMC,kBAAkB,GAAG,kCAAc;AAAEV,IAAAA,YAAY,EAAZA,YAAF;AAAgBS,IAAAA,cAAc,EAAdA;AAAhB,GAAd,CAA3B;;AAKA,qBAA2C,+BACzCX,MADyC,EAEzCC,2BAFyC,CAA3C;AAAA,MAAQY,oBAAR,gBAAQA,oBAAR;AAAA,MAA8BC,QAA9B,gBAA8BA,QAA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAP;AACD,CARM","sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel } from 'stream-chat';\n\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n TranslationContextValue,\n TranslationProvider,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/master/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n};\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { children, client, closeConnectionOnBackground = true, i18nInstance, style } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslationContextValue>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n /**\n * Setup muted user listener\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n useEffect(() => {\n if (client.setUserAgent) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n }\n }, []);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n const chatContext = useCreateChatContext({\n channel,\n client,\n connectionRecovering,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider value={translators}>\n <ThemeProvider style={style}>{children}</ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports["default"] = void 0;
|
|
5
|
+
|
|
6
|
+
var _reactNativeUrlPolyfill = require("react-native-url-polyfill");
|
|
7
|
+
|
|
8
|
+
var _default = function _default() {
|
|
9
|
+
(0, _reactNativeUrlPolyfill.setupURLPolyfill)();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports["default"] = _default;
|
|
13
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["init.ts"],"names":[],"mappings":";;;;;AAAA;;eAEe,oBAAM;AACnB;AACD,C","sourcesContent":["import { setupURLPolyfill } from 'react-native-url-polyfill';\n\nexport default () => {\n setupURLPolyfill();\n};\n"]}
|
|
@@ -7,20 +7,23 @@ var _reactNative = require("react-native");
|
|
|
7
7
|
|
|
8
8
|
function getResizedImageUrl(_ref) {
|
|
9
9
|
var height = _ref.height,
|
|
10
|
+
_ref$resize = _ref.resize,
|
|
11
|
+
resize = _ref$resize === void 0 ? 'clip' : _ref$resize,
|
|
10
12
|
url = _ref.url,
|
|
11
13
|
width = _ref.width;
|
|
12
|
-
var isResizableUrl = url.includes('
|
|
14
|
+
var isResizableUrl = url.includes('.stream-io-cdn.com');
|
|
13
15
|
if (!isResizableUrl || !height && !width) return url;
|
|
14
|
-
var
|
|
16
|
+
var parsedUrl = new URL(url);
|
|
15
17
|
|
|
16
18
|
if (height) {
|
|
17
|
-
|
|
19
|
+
parsedUrl.searchParams.set('h', "" + _reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(height)));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
if (width) {
|
|
21
|
-
|
|
23
|
+
parsedUrl.searchParams.set('w', "" + _reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(width)));
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
parsedUrl.searchParams.set('resize', "" + resize);
|
|
27
|
+
return parsedUrl.toString();
|
|
25
28
|
}
|
|
26
29
|
//# sourceMappingURL=getResizedImageUrl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getResizedImageUrl.ts"],"names":["getResizedImageUrl","height","url","width","isResizableUrl","includes","
|
|
1
|
+
{"version":3,"sources":["getResizedImageUrl.ts"],"names":["getResizedImageUrl","height","resize","url","width","isResizableUrl","includes","parsedUrl","URL","searchParams","set","PixelRatio","getPixelSizeForLayoutSize","Number","toString"],"mappings":";;;;;AAAA;;AAqBO,SAASA,kBAAT,OAKsB;AAAA,MAJ3BC,MAI2B,QAJ3BA,MAI2B;AAAA,yBAH3BC,MAG2B;AAAA,MAH3BA,MAG2B,4BAHlB,MAGkB;AAAA,MAF3BC,GAE2B,QAF3BA,GAE2B;AAAA,MAD3BC,KAC2B,QAD3BA,KAC2B;AAE3B,MAAMC,cAAc,GAAGF,GAAG,CAACG,QAAJ,CAAa,oBAAb,CAAvB;AACA,MAAI,CAACD,cAAD,IAAoB,CAACJ,MAAD,IAAW,CAACG,KAApC,EAA4C,OAAOD,GAAP;AAE5C,MAAMI,SAAS,GAAG,IAAIC,GAAJ,CAAQL,GAAR,CAAlB;;AAEA,MAAIF,MAAJ,EAAY;AACVM,IAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,GAA3B,OAAmCC,wBAAWC,yBAAX,CAAqCC,MAAM,CAACZ,MAAD,CAA3C,CAAnC;AACD;;AAED,MAAIG,KAAJ,EAAW;AACTG,IAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,GAA3B,OAAmCC,wBAAWC,yBAAX,CAAqCC,MAAM,CAACT,KAAD,CAA3C,CAAnC;AACD;;AAEDG,EAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,QAA3B,OAAwCR,MAAxC;AAEA,SAAOK,SAAS,CAACO,QAAV,EAAP;AACD","sourcesContent":["import { PixelRatio } from 'react-native';\n\ntype GetResizedImageUrlParams = {\n url: string;\n height?: string | number;\n resize?: 'clip' | 'crop' | 'fill' | 'scale';\n width?: string | number;\n};\n\n/**\n * Any file or image upload done through stream's chat SDK or components get uploaded\n * to CloudFront CDN. Following function returns a url of resized image (to given width and height).\n * It can be used to avoid rendering heavy images on UI, for the sake of performance.\n *\n * This function accepts an object with following properties:\n * - height: height of the resized image.\n * - url: url of the image.\n * - width: width of the resized image.\n *\n * @returns {string} Url of the image with given height and width.\n */\nexport function getResizedImageUrl({\n height,\n resize = 'clip',\n url,\n width,\n}: GetResizedImageUrlParams) {\n // Check if url belongs to cloudfront CDN\n const isResizableUrl = url.includes('.stream-io-cdn.com');\n if (!isResizableUrl || (!height && !width)) return url;\n\n const parsedUrl = new URL(url);\n\n if (height) {\n parsedUrl.searchParams.set('h', `${PixelRatio.getPixelSizeForLayoutSize(Number(height))}`);\n }\n\n if (width) {\n parsedUrl.searchParams.set('w', `${PixelRatio.getPixelSizeForLayoutSize(Number(width))}`);\n }\n\n parsedUrl.searchParams.set('resize', `${resize}`);\n\n return parsedUrl.toString();\n}\n"]}
|
|
@@ -33,6 +33,8 @@ var _TranslationContext = require("../../contexts/translationContext/Translation
|
|
|
33
33
|
|
|
34
34
|
var _useStreami18n = require("../../hooks/useStreami18n");
|
|
35
35
|
|
|
36
|
+
var _init = _interopRequireDefault(require("../../init"));
|
|
37
|
+
|
|
36
38
|
var _native = require("../../native");
|
|
37
39
|
|
|
38
40
|
var _version = require("../../version.json");
|
|
@@ -44,6 +46,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
44
46
|
|
|
45
47
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
48
|
|
|
49
|
+
(0, _init["default"])();
|
|
50
|
+
|
|
47
51
|
var ChatWithContext = function ChatWithContext(props) {
|
|
48
52
|
var children = props.children,
|
|
49
53
|
client = props.client,
|
|
@@ -104,7 +108,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
104
108
|
__self: _this,
|
|
105
109
|
__source: {
|
|
106
110
|
fileName: _jsxFileName,
|
|
107
|
-
lineNumber:
|
|
111
|
+
lineNumber: 176,
|
|
108
112
|
columnNumber: 5
|
|
109
113
|
}
|
|
110
114
|
}, _react["default"].createElement(_TranslationContext.TranslationProvider, {
|
|
@@ -112,7 +116,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
112
116
|
__self: _this,
|
|
113
117
|
__source: {
|
|
114
118
|
fileName: _jsxFileName,
|
|
115
|
-
lineNumber:
|
|
119
|
+
lineNumber: 177,
|
|
116
120
|
columnNumber: 7
|
|
117
121
|
}
|
|
118
122
|
}, _react["default"].createElement(_ThemeContext.ThemeProvider, {
|
|
@@ -120,7 +124,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
120
124
|
__self: _this,
|
|
121
125
|
__source: {
|
|
122
126
|
fileName: _jsxFileName,
|
|
123
|
-
lineNumber:
|
|
127
|
+
lineNumber: 178,
|
|
124
128
|
columnNumber: 9
|
|
125
129
|
}
|
|
126
130
|
}, children)));
|
|
@@ -136,7 +140,7 @@ var Chat = function Chat(props) {
|
|
|
136
140
|
__self: _this,
|
|
137
141
|
__source: {
|
|
138
142
|
fileName: _jsxFileName,
|
|
139
|
-
lineNumber:
|
|
143
|
+
lineNumber: 212,
|
|
140
144
|
columnNumber: 10
|
|
141
145
|
}
|
|
142
146
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Chat.tsx"],"names":["ChatWithContext","props","children","client","closeConnectionOnBackground","i18nInstance","style","channel","setChannel","t","key","tDateTimeParser","input","translators","setTranslators","loadingTranslators","connectionRecovering","isOnline","mutedUsers","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","setActiveChannel","newChannel","chatContext","Chat"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;;AAEA;;AAGA;;;;;;;;;AA+FA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAGtBC,KAHsB,EAInB;AACH,MAAQC,QAAR,GAAsFD,KAAtF,CAAQC,QAAR;AAAA,MAAkBC,MAAlB,GAAsFF,KAAtF,CAAkBE,MAAlB;AAAA,8BAAsFF,KAAtF,CAA0BG,2BAA1B;AAAA,MAA0BA,2BAA1B,sCAAwD,IAAxD;AAAA,MAA8DC,YAA9D,GAAsFJ,KAAtF,CAA8DI,YAA9D;AAAA,MAA4EC,KAA5E,GAAsFL,KAAtF,CAA4EK,KAA5E;;AAEA,kBAA8B,sBAA9B;AAAA;AAAA,MAAOC,OAAP;AAAA,MAAgBC,UAAhB;;AACA,mBAAsC,qBAAkC;AACtEC,IAAAA,CAAC,EAAE,WAACC,GAAD;AAAA,aAAiBA,GAAjB;AAAA,KADmE;AAEtEC,IAAAA,eAAe,EAAE,yBAACC,KAAD;AAAA,aAAoC,uBAAMA,KAAN,CAApC;AAAA;AAFqD,GAAlC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AAQA,MAAMC,kBAAkB,GAAG,kCAAc;AAAEV,IAAAA,YAAY,EAAZA,YAAF;AAAgBS,IAAAA,cAAc,EAAdA;AAAhB,GAAd,CAA3B;;AAKA,qBAA2C,+BACzCX,MADyC,EAEzCC,2BAFyC,CAA3C;AAAA,MAAQY,oBAAR,gBAAQA,oBAAR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AK,EAALA;AAAvB,KAAoCL,KAApC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAP;AACD,CARM","sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel } from 'stream-chat';\n\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n TranslationContextValue,\n TranslationProvider,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\n\nimport { SDK } from '../../native';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/master/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n};\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { children, client, closeConnectionOnBackground = true, i18nInstance, style } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslationContextValue>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n /**\n * Setup muted user listener\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n useEffect(() => {\n if (client.setUserAgent) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n }\n }, []);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n const chatContext = useCreateChatContext({\n channel,\n client,\n connectionRecovering,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider value={translators}>\n <ThemeProvider style={style}>{children}</ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["Chat.tsx"],"names":["ChatWithContext","props","children","client","closeConnectionOnBackground","i18nInstance","style","channel","setChannel","t","key","tDateTimeParser","input","translators","setTranslators","loadingTranslators","connectionRecovering","isOnline","mutedUsers","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","setActiveChannel","newChannel","chatContext","Chat"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;;AACA;;AAEA;;AAGA;;;;;;;;;AAEA;;AA+FA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAGtBC,KAHsB,EAInB;AACH,MAAQC,QAAR,GAAsFD,KAAtF,CAAQC,QAAR;AAAA,MAAkBC,MAAlB,GAAsFF,KAAtF,CAAkBE,MAAlB;AAAA,8BAAsFF,KAAtF,CAA0BG,2BAA1B;AAAA,MAA0BA,2BAA1B,sCAAwD,IAAxD;AAAA,MAA8DC,YAA9D,GAAsFJ,KAAtF,CAA8DI,YAA9D;AAAA,MAA4EC,KAA5E,GAAsFL,KAAtF,CAA4EK,KAA5E;;AAEA,kBAA8B,sBAA9B;AAAA;AAAA,MAAOC,OAAP;AAAA,MAAgBC,UAAhB;;AACA,mBAAsC,qBAAkC;AACtEC,IAAAA,CAAC,EAAE,WAACC,GAAD;AAAA,aAAiBA,GAAjB;AAAA,KADmE;AAEtEC,IAAAA,eAAe,EAAE,yBAACC,KAAD;AAAA,aAAoC,uBAAMA,KAAN,CAApC;AAAA;AAFqD,GAAlC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AAQA,MAAMC,kBAAkB,GAAG,kCAAc;AAAEV,IAAAA,YAAY,EAAZA,YAAF;AAAgBS,IAAAA,cAAc,EAAdA;AAAhB,GAAd,CAA3B;;AAKA,qBAA2C,+BACzCX,MADyC,EAEzCC,2BAFyC,CAA3C;AAAA,MAAQY,oBAAR,gBAAQA,oBAAR;AAAA,MAA8BC,QAA9B,gBAA8BA,QAA9B;;AAQA,MAAMC,UAAU,GAAG,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;AAAA,KAAP;AACD,CARM","sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel } from 'stream-chat';\n\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n TranslationContextValue,\n TranslationProvider,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/master/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n};\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { children, client, closeConnectionOnBackground = true, i18nInstance, style } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslationContextValue>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n /**\n * Setup muted user listener\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n useEffect(() => {\n if (client.setUserAgent) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n }\n }, []);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n const chatContext = useCreateChatContext({\n channel,\n client,\n connectionRecovering,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider value={translators}>\n <ThemeProvider style={style}>{children}</ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports["default"] = void 0;
|
|
5
|
+
|
|
6
|
+
var _reactNativeUrlPolyfill = require("react-native-url-polyfill");
|
|
7
|
+
|
|
8
|
+
var _default = function _default() {
|
|
9
|
+
(0, _reactNativeUrlPolyfill.setupURLPolyfill)();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports["default"] = _default;
|
|
13
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["init.ts"],"names":[],"mappings":";;;;;AAAA;;eAEe,oBAAM;AACnB;AACD,C","sourcesContent":["import { setupURLPolyfill } from 'react-native-url-polyfill';\n\nexport default () => {\n setupURLPolyfill();\n};\n"]}
|
|
@@ -7,20 +7,23 @@ var _reactNative = require("react-native");
|
|
|
7
7
|
|
|
8
8
|
function getResizedImageUrl(_ref) {
|
|
9
9
|
var height = _ref.height,
|
|
10
|
+
_ref$resize = _ref.resize,
|
|
11
|
+
resize = _ref$resize === void 0 ? 'clip' : _ref$resize,
|
|
10
12
|
url = _ref.url,
|
|
11
13
|
width = _ref.width;
|
|
12
|
-
var isResizableUrl = url.includes('
|
|
14
|
+
var isResizableUrl = url.includes('.stream-io-cdn.com');
|
|
13
15
|
if (!isResizableUrl || !height && !width) return url;
|
|
14
|
-
var
|
|
16
|
+
var parsedUrl = new URL(url);
|
|
15
17
|
|
|
16
18
|
if (height) {
|
|
17
|
-
|
|
19
|
+
parsedUrl.searchParams.set('h', "" + _reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(height)));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
if (width) {
|
|
21
|
-
|
|
23
|
+
parsedUrl.searchParams.set('w', "" + _reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(width)));
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
parsedUrl.searchParams.set('resize', "" + resize);
|
|
27
|
+
return parsedUrl.toString();
|
|
25
28
|
}
|
|
26
29
|
//# sourceMappingURL=getResizedImageUrl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getResizedImageUrl.ts"],"names":["getResizedImageUrl","height","url","width","isResizableUrl","includes","
|
|
1
|
+
{"version":3,"sources":["getResizedImageUrl.ts"],"names":["getResizedImageUrl","height","resize","url","width","isResizableUrl","includes","parsedUrl","URL","searchParams","set","PixelRatio","getPixelSizeForLayoutSize","Number","toString"],"mappings":";;;;;AAAA;;AAqBO,SAASA,kBAAT,OAKsB;AAAA,MAJ3BC,MAI2B,QAJ3BA,MAI2B;AAAA,yBAH3BC,MAG2B;AAAA,MAH3BA,MAG2B,4BAHlB,MAGkB;AAAA,MAF3BC,GAE2B,QAF3BA,GAE2B;AAAA,MAD3BC,KAC2B,QAD3BA,KAC2B;AAE3B,MAAMC,cAAc,GAAGF,GAAG,CAACG,QAAJ,CAAa,oBAAb,CAAvB;AACA,MAAI,CAACD,cAAD,IAAoB,CAACJ,MAAD,IAAW,CAACG,KAApC,EAA4C,OAAOD,GAAP;AAE5C,MAAMI,SAAS,GAAG,IAAIC,GAAJ,CAAQL,GAAR,CAAlB;;AAEA,MAAIF,MAAJ,EAAY;AACVM,IAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,GAA3B,OAAmCC,wBAAWC,yBAAX,CAAqCC,MAAM,CAACZ,MAAD,CAA3C,CAAnC;AACD;;AAED,MAAIG,KAAJ,EAAW;AACTG,IAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,GAA3B,OAAmCC,wBAAWC,yBAAX,CAAqCC,MAAM,CAACT,KAAD,CAA3C,CAAnC;AACD;;AAEDG,EAAAA,SAAS,CAACE,YAAV,CAAuBC,GAAvB,CAA2B,QAA3B,OAAwCR,MAAxC;AAEA,SAAOK,SAAS,CAACO,QAAV,EAAP;AACD","sourcesContent":["import { PixelRatio } from 'react-native';\n\ntype GetResizedImageUrlParams = {\n url: string;\n height?: string | number;\n resize?: 'clip' | 'crop' | 'fill' | 'scale';\n width?: string | number;\n};\n\n/**\n * Any file or image upload done through stream's chat SDK or components get uploaded\n * to CloudFront CDN. Following function returns a url of resized image (to given width and height).\n * It can be used to avoid rendering heavy images on UI, for the sake of performance.\n *\n * This function accepts an object with following properties:\n * - height: height of the resized image.\n * - url: url of the image.\n * - width: width of the resized image.\n *\n * @returns {string} Url of the image with given height and width.\n */\nexport function getResizedImageUrl({\n height,\n resize = 'clip',\n url,\n width,\n}: GetResizedImageUrlParams) {\n // Check if url belongs to cloudfront CDN\n const isResizableUrl = url.includes('.stream-io-cdn.com');\n if (!isResizableUrl || (!height && !width)) return url;\n\n const parsedUrl = new URL(url);\n\n if (height) {\n parsedUrl.searchParams.set('h', `${PixelRatio.getPixelSizeForLayoutSize(Number(height))}`);\n }\n\n if (width) {\n parsedUrl.searchParams.set('w', `${PixelRatio.getPixelSizeForLayoutSize(Number(width))}`);\n }\n\n parsedUrl.searchParams.set('resize', `${resize}`);\n\n return parsedUrl.toString();\n}\n"]}
|
package/lib/module/version.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare type GetResizedImageUrlParams = {
|
|
2
2
|
url: string;
|
|
3
3
|
height?: string | number;
|
|
4
|
+
resize?: 'clip' | 'crop' | 'fill' | 'scale';
|
|
4
5
|
width?: string | number;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
@@ -15,5 +16,5 @@ declare type GetResizedImageUrlParams = {
|
|
|
15
16
|
*
|
|
16
17
|
* @returns {string} Url of the image with given height and width.
|
|
17
18
|
*/
|
|
18
|
-
export declare function getResizedImageUrl({ height, url, width }: GetResizedImageUrlParams): string;
|
|
19
|
+
export declare function getResizedImageUrl({ height, resize, url, width, }: GetResizedImageUrlParams): string;
|
|
19
20
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.7",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -27,8 +27,6 @@
|
|
|
27
27
|
"lint-fix-translations": "prettier --check 'src/i18n/*.json' --write 'src/i18n/*.json' .eslintrc.json ../.prettierrc .babelrc",
|
|
28
28
|
"build-translations": "rm -rf .tmpi18ncache || true && mkdir .tmpi18ncache && yarn run babel --config-file ./babel.i18next-extract.json 'src/**/*.{js,jsx,ts,tsx}' --out-dir '.tmpi18ncache/' && rm -rf .tmpi18ncache && prettier --write 'src/i18n/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc",
|
|
29
29
|
"copy-translations": "echo '\u001b[34mℹ\u001b[0m Copying translation files to \u001b[34mlib/typescript/i18n\u001b[0m' && cp -R -f ./src/i18n ./lib/typescript/i18n && echo '\u001b[32m✓\u001b[0m Done Copying Translations'",
|
|
30
|
-
"docs": "styleguidist build",
|
|
31
|
-
"docs-server": "styleguidist server",
|
|
32
30
|
"eslint": "eslint 'src/**/*.{js,md,ts,jsx,tsx}' --max-warnings 0",
|
|
33
31
|
"lint": "prettier --ignore-path ../.prettierignore --list-different 'src/**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc && eslint 'src/**/*.{js,ts,tsx,md}' --max-warnings 0 && yarn run validate-translations",
|
|
34
32
|
"lint-fix": "prettier --ignore-path ../.prettierignore --write 'src/**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc && eslint --fix 'src/**/*.{js,ts,tsx,md}' --max-warnings 0",
|
|
@@ -80,6 +78,7 @@
|
|
|
80
78
|
"path": "0.12.7",
|
|
81
79
|
"react-art": "^17.0.2",
|
|
82
80
|
"react-native-markdown-package": "1.8.1",
|
|
81
|
+
"react-native-url-polyfill": "^1.3.0",
|
|
83
82
|
"stream-chat": "6.0.0"
|
|
84
83
|
},
|
|
85
84
|
"peerDependencies": {
|
|
@@ -138,7 +137,6 @@
|
|
|
138
137
|
"react-native-svg": "12.1.1",
|
|
139
138
|
"react-native-typescript-transformer": "1.2.13",
|
|
140
139
|
"react-native-web": "0.15.0",
|
|
141
|
-
"react-styleguidist": "11.1.6",
|
|
142
140
|
"react-test-renderer": "17.0.2",
|
|
143
141
|
"typescript": "4.4.3",
|
|
144
142
|
"uuid": "8.3.2",
|
|
@@ -97,7 +97,7 @@ describe('buildGallery', () => {
|
|
|
97
97
|
it('thumbnail size should be smaller than the limits set by sizeConfig', () => {
|
|
98
98
|
const bigImage = generateImageAttachment({
|
|
99
99
|
image_url:
|
|
100
|
-
'https://stream-io
|
|
100
|
+
'https://us-east.stream-io-cdn.com/23kn4k2j3n4k2n3k4n23?sig=34k23n4k23nk423&h=*&w=*&resize=*',
|
|
101
101
|
original_height: 1200,
|
|
102
102
|
original_width: 900,
|
|
103
103
|
});
|
|
@@ -107,13 +107,13 @@ describe('buildGallery', () => {
|
|
|
107
107
|
sizeConfig: defaultSizeConfig,
|
|
108
108
|
});
|
|
109
109
|
const t1 = tg1[0][0];
|
|
110
|
-
expect(t1.url.includes(
|
|
110
|
+
expect(t1.url.includes(`&h=${PixelRatio.getPixelSizeForLayoutSize(t1.height)}`)).toBe(true);
|
|
111
111
|
expect(t1.url.includes(`&w=${PixelRatio.getPixelSizeForLayoutSize(t1.width)}`)).toBe(true);
|
|
112
112
|
expect(t1.url.includes(`&resize=clip`)).toBe(true);
|
|
113
113
|
|
|
114
114
|
const smallImage = generateImageAttachment({
|
|
115
115
|
image_url:
|
|
116
|
-
'https://stream-io
|
|
116
|
+
'https://us-east.stream-io-cdn.com/23kn4k2j3n4k2n3k4n23?sig=34k23n4k23nk423&h=*&w=*&resize=*',
|
|
117
117
|
original_height: 30,
|
|
118
118
|
original_width: 20,
|
|
119
119
|
});
|
|
@@ -124,7 +124,7 @@ describe('buildGallery', () => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
const t2 = tg2[0][0];
|
|
127
|
-
expect(t2.url.includes(
|
|
127
|
+
expect(t2.url.includes(`&h=*`)).toBe(true);
|
|
128
128
|
expect(t2.url.includes(`&w=*`)).toBe(true);
|
|
129
129
|
expect(t2.url.includes(`&resize=*`)).toBe(true);
|
|
130
130
|
});
|
|
@@ -18,12 +18,15 @@ import {
|
|
|
18
18
|
TranslationProvider,
|
|
19
19
|
} from '../../contexts/translationContext/TranslationContext';
|
|
20
20
|
import { useStreami18n } from '../../hooks/useStreami18n';
|
|
21
|
+
import init from '../../init';
|
|
21
22
|
|
|
22
23
|
import { SDK } from '../../native';
|
|
23
24
|
import type { DefaultStreamChatGenerics } from '../../types/types';
|
|
24
25
|
import type { Streami18n } from '../../utils/Streami18n';
|
|
25
26
|
import { version } from '../../version.json';
|
|
26
27
|
|
|
28
|
+
init();
|
|
29
|
+
|
|
27
30
|
export type ChatProps<
|
|
28
31
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
29
32
|
> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> & {
|
package/src/init.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { PixelRatio } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { getResizedImageUrl } from '../getResizedImageUrl';
|
|
4
|
+
|
|
5
|
+
describe('getResizedImageUrl', () => {
|
|
6
|
+
it('should return same url if its not cloudfront cdn', () => {
|
|
7
|
+
const testUrl = 'http://foo.com/blah_(wikipedia)#cite-1';
|
|
8
|
+
|
|
9
|
+
const resizedUrl = getResizedImageUrl({ height: 100, url: testUrl, width: 100 });
|
|
10
|
+
expect(resizedUrl).toEqual(testUrl);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should append given height, width and resize mode to url', () => {
|
|
14
|
+
const testUrl = 'http://us-east.stream-io-cdn.com/blah';
|
|
15
|
+
|
|
16
|
+
const testConfigs = [
|
|
17
|
+
{ height: 100, resize: 'scale', width: 100 },
|
|
18
|
+
{ height: 200, resize: 'fill', width: 300 },
|
|
19
|
+
{ height: 1000, resize: 'clip', width: 10 },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
testConfigs.forEach(({ height, resize, width }) => {
|
|
23
|
+
const resizedUrl = getResizedImageUrl({ height, resize, url: testUrl, width });
|
|
24
|
+
const parsedUrl = new URL(resizedUrl);
|
|
25
|
+
expect(parsedUrl.searchParams.get('h')).toEqual(
|
|
26
|
+
`${PixelRatio.getPixelSizeForLayoutSize(height)}`,
|
|
27
|
+
);
|
|
28
|
+
expect(parsedUrl.searchParams.get('w')).toEqual(
|
|
29
|
+
`${PixelRatio.getPixelSizeForLayoutSize(width)}`,
|
|
30
|
+
);
|
|
31
|
+
expect(parsedUrl.searchParams.get('resize')).toEqual(resize);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should replace wildcards with given height, width and resize mode within url', () => {
|
|
36
|
+
const testUrl = 'http://us-east.stream-io-cdn.com/blah?h=*&w=*&resize=*';
|
|
37
|
+
|
|
38
|
+
const testConfigs = [
|
|
39
|
+
{ height: 100, resize: 'scale', width: 100 },
|
|
40
|
+
{ height: 200, resize: 'fill', width: 300 },
|
|
41
|
+
{ height: 1000, resize: 'clip', width: 10 },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
testConfigs.forEach(({ height, resize, width }) => {
|
|
45
|
+
const resizedUrl = getResizedImageUrl({ height, resize, url: testUrl, width });
|
|
46
|
+
const parsedUrl = new URL(resizedUrl);
|
|
47
|
+
expect(parsedUrl.searchParams.get('h')).toEqual(
|
|
48
|
+
`${PixelRatio.getPixelSizeForLayoutSize(height)}`,
|
|
49
|
+
);
|
|
50
|
+
expect(parsedUrl.searchParams.get('w')).toEqual(
|
|
51
|
+
`${PixelRatio.getPixelSizeForLayoutSize(width)}`,
|
|
52
|
+
);
|
|
53
|
+
expect(parsedUrl.searchParams.get('resize')).toEqual(resize);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -3,6 +3,7 @@ import { PixelRatio } from 'react-native';
|
|
|
3
3
|
type GetResizedImageUrlParams = {
|
|
4
4
|
url: string;
|
|
5
5
|
height?: string | number;
|
|
6
|
+
resize?: 'clip' | 'crop' | 'fill' | 'scale';
|
|
6
7
|
width?: string | number;
|
|
7
8
|
};
|
|
8
9
|
|
|
@@ -18,26 +19,27 @@ type GetResizedImageUrlParams = {
|
|
|
18
19
|
*
|
|
19
20
|
* @returns {string} Url of the image with given height and width.
|
|
20
21
|
*/
|
|
21
|
-
export function getResizedImageUrl({
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
export function getResizedImageUrl({
|
|
23
|
+
height,
|
|
24
|
+
resize = 'clip',
|
|
25
|
+
url,
|
|
26
|
+
width,
|
|
27
|
+
}: GetResizedImageUrlParams) {
|
|
28
|
+
// Check if url belongs to cloudfront CDN
|
|
29
|
+
const isResizableUrl = url.includes('.stream-io-cdn.com');
|
|
24
30
|
if (!isResizableUrl || (!height && !width)) return url;
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
const parsedUrl = new URL(url);
|
|
27
33
|
|
|
28
34
|
if (height) {
|
|
29
|
-
|
|
30
|
-
'h=*',
|
|
31
|
-
`h=${PixelRatio.getPixelSizeForLayoutSize(Number(height))}`,
|
|
32
|
-
);
|
|
35
|
+
parsedUrl.searchParams.set('h', `${PixelRatio.getPixelSizeForLayoutSize(Number(height))}`);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
if (width) {
|
|
36
|
-
|
|
37
|
-
'w=*',
|
|
38
|
-
`w=${PixelRatio.getPixelSizeForLayoutSize(Number(width))}`,
|
|
39
|
-
);
|
|
39
|
+
parsedUrl.searchParams.set('w', `${PixelRatio.getPixelSizeForLayoutSize(Number(width))}`);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
parsedUrl.searchParams.set('resize', `${resize}`);
|
|
43
|
+
|
|
44
|
+
return parsedUrl.toString();
|
|
43
45
|
}
|
package/src/version.json
CHANGED