@cometchat/chat-uikit-react-native 5.1.1 → 5.1.2
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/package.json +4 -4
- package/src/CometChatMessageList/CometChatMessageList.tsx +103 -45
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +13 -29
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +8 -5
- package/src/extensions/Polls/Polls.tsx +50 -22
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -1
- package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +57 -45
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +121 -74
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.d.ts +0 -79
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js +0 -152
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js.map +0 -1
- package/lib/shared/resources/CometChatLocalize/index.d.ts +0 -2
- package/lib/shared/resources/CometChatLocalize/index.js +0 -3
- package/lib/shared/resources/CometChatLocalize/index.js.map +0 -1
- package/lib/shared/resources/CometChatLocalize/resources/ar/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/de/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/en/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/es/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/fr/translation.json +0 -446
- package/lib/shared/resources/CometChatLocalize/resources/hi/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/hu/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/lt/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/ms/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/pt/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/ru/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/sv/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/zh/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +0 -446
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.d.ts +0 -29
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +0 -29
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js.map +0 -1
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
import React, { useLayoutEffect, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
Image,
|
|
5
|
-
Modal,
|
|
6
|
-
SafeAreaView,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
TouchableOpacity,
|
|
9
|
-
View,
|
|
10
|
-
} from "react-native";
|
|
2
|
+
import { ActivityIndicator, Image, Modal, StyleSheet, TouchableOpacity, View } from "react-native";
|
|
3
|
+
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
|
|
11
4
|
import { ReactNativeZoomableViewWithGestures } from "../../libs/ImageZoom";
|
|
12
|
-
import {
|
|
5
|
+
import { Icon } from "../../icons/Icon";
|
|
13
6
|
|
|
14
7
|
export const ImageViewerModal = ({ imageUrl, isVisible, onClose }: any) => {
|
|
15
8
|
const [downloaded, setDownloaded] = useState(false);
|
|
9
|
+
const insets = useSafeAreaInsets();
|
|
10
|
+
|
|
16
11
|
useLayoutEffect(() => {
|
|
17
|
-
|
|
12
|
+
// include imageUrl as dep so it re-runs when URL changes
|
|
13
|
+
if (!imageUrl) return;
|
|
14
|
+
Image.prefetch(typeof imageUrl === "string" ? imageUrl : imageUrl.uri).then((res) => {
|
|
18
15
|
setDownloaded(res);
|
|
19
16
|
});
|
|
20
|
-
|
|
21
|
-
Image.getSize(
|
|
22
|
-
imageUrl.uri,
|
|
23
|
-
(res) => {
|
|
24
|
-
console.log("success : ", res);
|
|
25
|
-
},
|
|
26
|
-
(res) => {
|
|
27
|
-
console.log("error : ", res);
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
}, []);
|
|
17
|
+
}, [imageUrl]);
|
|
31
18
|
|
|
32
19
|
return (
|
|
33
20
|
<Modal animationType='slide' transparent={false} visible={isVisible} onRequestClose={onClose}>
|
|
34
|
-
|
|
21
|
+
{/* keep SafeAreaView so bottom inset is handled too */}
|
|
22
|
+
<SafeAreaView style={styles.centeredView} edges={["bottom"]}>
|
|
23
|
+
<View
|
|
24
|
+
style={[
|
|
25
|
+
styles.header,
|
|
26
|
+
{
|
|
27
|
+
// push header below the notch/status bar
|
|
28
|
+
paddingTop: insets.top,
|
|
29
|
+
height: 60 + insets.top,
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
>
|
|
33
|
+
<TouchableOpacity
|
|
34
|
+
style={[
|
|
35
|
+
styles.closeButton,
|
|
36
|
+
{
|
|
37
|
+
// respect left inset (very useful on iPhone with rounded corners)
|
|
38
|
+
marginLeft: Math.max(10, insets.left + 6),
|
|
39
|
+
},
|
|
40
|
+
]}
|
|
41
|
+
onPress={onClose}
|
|
42
|
+
>
|
|
43
|
+
<Icon name='arrow-back-fill' color={"#fff"} height={22} width={22} />
|
|
44
|
+
</TouchableOpacity>
|
|
45
|
+
</View>
|
|
46
|
+
|
|
35
47
|
<View style={styles.container}>
|
|
36
|
-
<View style={styles.header}>
|
|
37
|
-
<TouchableOpacity style={styles.closeButton} onPress={onClose}>
|
|
38
|
-
<Image source={ICONS.backIcon} style={{ tintColor: "#fff", height: 20, width: 20 }} />
|
|
39
|
-
</TouchableOpacity>
|
|
40
|
-
</View>
|
|
41
48
|
{downloaded ? (
|
|
42
49
|
<View style={styles.imageContainer}>
|
|
43
50
|
<ReactNativeZoomableViewWithGestures onSwipeDown={onClose}>
|
|
@@ -45,7 +52,9 @@ export const ImageViewerModal = ({ imageUrl, isVisible, onClose }: any) => {
|
|
|
45
52
|
</ReactNativeZoomableViewWithGestures>
|
|
46
53
|
</View>
|
|
47
54
|
) : (
|
|
48
|
-
<
|
|
55
|
+
<View style={styles.loaderContainer}>
|
|
56
|
+
<ActivityIndicator color={"#fff"} size='large' />
|
|
57
|
+
</View>
|
|
49
58
|
)}
|
|
50
59
|
</View>
|
|
51
60
|
</SafeAreaView>
|
|
@@ -56,38 +65,41 @@ export const ImageViewerModal = ({ imageUrl, isVisible, onClose }: any) => {
|
|
|
56
65
|
const styles = StyleSheet.create({
|
|
57
66
|
centeredView: {
|
|
58
67
|
flex: 1,
|
|
59
|
-
|
|
60
|
-
elevation: 1,
|
|
68
|
+
backgroundColor: "#000",
|
|
61
69
|
},
|
|
62
70
|
container: {
|
|
71
|
+
flex: 1,
|
|
72
|
+
backgroundColor: "#000",
|
|
73
|
+
},
|
|
74
|
+
loaderContainer: {
|
|
63
75
|
flex: 1,
|
|
64
76
|
justifyContent: "center",
|
|
65
77
|
alignItems: "center",
|
|
66
|
-
backgroundColor: "#000",
|
|
67
78
|
},
|
|
68
79
|
header: {
|
|
69
80
|
position: "absolute",
|
|
70
81
|
top: 0,
|
|
82
|
+
left: 0,
|
|
83
|
+
right: 0,
|
|
71
84
|
backgroundColor: "transparent",
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
zIndex: 1000,
|
|
86
|
+
elevation: 50,
|
|
87
|
+
justifyContent: "center",
|
|
75
88
|
},
|
|
76
89
|
imageContainer: {
|
|
77
90
|
flex: 1,
|
|
78
|
-
|
|
79
|
-
width: "100%",
|
|
80
|
-
},
|
|
81
|
-
imageStyle: {
|
|
82
|
-
width: "100%",
|
|
83
|
-
height: "100%",
|
|
91
|
+
marginVertical: 60,
|
|
84
92
|
},
|
|
85
93
|
closeButton: {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
width: 60,
|
|
94
|
+
height: 44,
|
|
95
|
+
width: 44,
|
|
89
96
|
justifyContent: "center",
|
|
90
97
|
alignItems: "center",
|
|
91
|
-
|
|
98
|
+
backgroundColor: "rgba(0,0,0,0.3)",
|
|
99
|
+
borderRadius: 22,
|
|
100
|
+
},
|
|
101
|
+
imageStyle: {
|
|
102
|
+
width: "100%",
|
|
103
|
+
height: "100%",
|
|
92
104
|
},
|
|
93
105
|
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import React, { useLayoutEffect, useState,
|
|
1
|
+
import React, { useLayoutEffect, useState, useRef, useCallback } from "react";
|
|
2
2
|
import {
|
|
3
|
-
Platform,
|
|
4
3
|
StyleProp,
|
|
5
4
|
Text,
|
|
6
5
|
TextStyle,
|
|
7
6
|
View,
|
|
8
7
|
ViewStyle,
|
|
9
8
|
TouchableOpacity,
|
|
9
|
+
LayoutChangeEvent,
|
|
10
|
+
TextLayoutEvent,
|
|
10
11
|
} from "react-native";
|
|
11
12
|
import {
|
|
12
13
|
CometChatMentionsFormatter,
|
|
@@ -14,24 +15,28 @@ import {
|
|
|
14
15
|
CometChatUrlsFormatter,
|
|
15
16
|
} from "../../formatters";
|
|
16
17
|
import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
|
|
18
|
+
import { t } from "../../resources/CometChatLocalizeNew/LocalizationManager";
|
|
17
19
|
|
|
18
20
|
export interface CometChatTextBubbleInterface {
|
|
19
|
-
|
|
20
|
-
* Text to be shown
|
|
21
|
-
*/
|
|
21
|
+
/*** text to be shown */
|
|
22
22
|
text?: string;
|
|
23
23
|
textStyle?: StyleProp<TextStyle>;
|
|
24
|
-
/**
|
|
25
|
-
* Text container style
|
|
26
|
-
*/
|
|
24
|
+
/** text container style */
|
|
27
25
|
textContainerStyle?: StyleProp<ViewStyle>;
|
|
28
26
|
textFormatters?: Array<
|
|
29
27
|
CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter
|
|
30
28
|
>;
|
|
29
|
+
/** number of lines to collapse to (default 4) */
|
|
30
|
+
collapseLines?: number;
|
|
31
|
+
/** style for the toggle container */
|
|
32
|
+
toggleContainerStyle?: StyleProp<ViewStyle>;
|
|
33
|
+
/** style for the toggle text */
|
|
34
|
+
toggleTextStyle?: StyleProp<TextStyle>;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export const CometChatTextBubble = (props: CometChatTextBubbleInterface) => {
|
|
34
38
|
const { textContainerStyle } = props;
|
|
39
|
+
|
|
35
40
|
return (
|
|
36
41
|
<View style={textContainerStyle}>
|
|
37
42
|
<CometChatTextBubbleText {...props} />
|
|
@@ -39,20 +44,39 @@ export const CometChatTextBubble = (props: CometChatTextBubbleInterface) => {
|
|
|
39
44
|
);
|
|
40
45
|
};
|
|
41
46
|
|
|
47
|
+
/**
|
|
48
|
+
* CometChatTextBubbleText
|
|
49
|
+
*
|
|
50
|
+
* - measure by actual container width (onLayout) so both iOS and Android measure correctly
|
|
51
|
+
* - robust measurement cache keyed by text+width so we don't re-measure unnecessarily
|
|
52
|
+
*/
|
|
42
53
|
export const CometChatTextBubbleText = (
|
|
43
54
|
props: Omit<CometChatTextBubbleInterface, "textContainerStyle">
|
|
44
55
|
) => {
|
|
45
|
-
const {t}= useCometChatTranslation()
|
|
46
|
-
const {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const { t } = useCometChatTranslation();
|
|
57
|
+
const {
|
|
58
|
+
text = "",
|
|
59
|
+
textFormatters,
|
|
60
|
+
textStyle,
|
|
61
|
+
collapseLines = 4,
|
|
62
|
+
toggleContainerStyle,
|
|
63
|
+
toggleTextStyle,
|
|
64
|
+
} = props;
|
|
65
|
+
|
|
66
|
+
const [formattedText, setFormattedText] = useState<string>(text);
|
|
67
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
68
|
+
const [isTruncatable, setIsTruncatable] = useState(false);
|
|
69
|
+
|
|
70
|
+
// store container width for accurate measurement
|
|
71
|
+
const [containerWidth, setContainerWidth] = useState<number | null>(null);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* measuredCache helps avoid re-measuring if the same text+width was already measured.
|
|
75
|
+
* Structure: { key: string } where key = `${text}::${width}`
|
|
76
|
+
*/
|
|
77
|
+
const measuredCacheRef = useRef<Record<string, boolean>>({});
|
|
78
|
+
|
|
79
|
+
// Only recompute formattedText when the text or textFormatters actually change.
|
|
56
80
|
useLayoutEffect(() => {
|
|
57
81
|
let finalText = text;
|
|
58
82
|
if (textFormatters && textFormatters.length) {
|
|
@@ -60,78 +84,101 @@ export const CometChatTextBubbleText = (
|
|
|
60
84
|
finalText = textFormatters[i].getFormattedText(finalText);
|
|
61
85
|
}
|
|
62
86
|
}
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (lines.length > 4) {
|
|
72
|
-
// Only set to true, never reset to false when a message is updated
|
|
73
|
-
// This preserves the truncated state when the message is updated (e.g., reactions added)
|
|
74
|
-
setIsTruncated(true);
|
|
87
|
+
|
|
88
|
+
// If text content actually changed, update formattedText and reset expansion.
|
|
89
|
+
// Do NOT reset on other prop changes (so adding reaction won't collapse/lose toggle).
|
|
90
|
+
if (finalText !== formattedText) {
|
|
91
|
+
setFormattedText(finalText as string);
|
|
92
|
+
setIsExpanded(false);
|
|
93
|
+
// measurement cache can stay, but remove entries for previous text (optional)
|
|
94
|
+
// measuredCacheRef.current = {}; // not required, we'll rely on keying by text+width
|
|
75
95
|
}
|
|
76
|
-
//
|
|
77
|
-
}
|
|
96
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
+
}, [
|
|
98
|
+
text /* only textFormatters intentionally omitted from deps if stable; if not stable include it */,
|
|
99
|
+
]);
|
|
78
100
|
|
|
79
|
-
//
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
// handler to capture container width whenever layout changes
|
|
102
|
+
const onContainerLayout = useCallback(
|
|
103
|
+
(e: LayoutChangeEvent) => {
|
|
104
|
+
const w = Math.round(e.nativeEvent.layout.width);
|
|
105
|
+
if (w && w !== containerWidth) {
|
|
106
|
+
setContainerWidth(w);
|
|
107
|
+
// Do NOT clear isExpanded here — measurement may change truncation but we want to
|
|
108
|
+
// preserve user's expanded/collapsed state unless the text itself changed.
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[containerWidth]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Called when hidden text is laid out; use it to determine lines count
|
|
115
|
+
const onMeasuredTextLayout = (e: TextLayoutEvent) => {
|
|
116
|
+
// We rely on containerWidth + formattedText as the measurement key
|
|
117
|
+
const key = `${formattedText}::${containerWidth ?? 0}`;
|
|
83
118
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
119
|
+
// If we've already measured this text at this width, skip
|
|
120
|
+
if (measuredCacheRef.current[key]) return;
|
|
121
|
+
|
|
122
|
+
const lines = e.nativeEvent.lines;
|
|
123
|
+
const isNowTruncatable = !!(lines && lines.length > collapseLines);
|
|
124
|
+
|
|
125
|
+
setIsTruncatable(isNowTruncatable);
|
|
126
|
+
measuredCacheRef.current[key] = isNowTruncatable;
|
|
87
127
|
};
|
|
88
128
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
129
|
+
const toggle = () => setIsExpanded((v) => !v);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Hidden measurement `Text`:
|
|
133
|
+
* - we render it only when we have containerWidth (so it can measure correctly)
|
|
134
|
+
* - style uses same font metrics as visible text because it inherits textStyle
|
|
135
|
+
* - opacity: 0 and position absolute so it does not affect layout
|
|
136
|
+
*
|
|
137
|
+
* Important: We key the hidden Text by formattedText + containerWidth so React remounts
|
|
138
|
+
* it and triggers onTextLayout when either changes.
|
|
139
|
+
*/
|
|
140
|
+
const hiddenTextKey = `${formattedText}::${containerWidth ?? 0}`;
|
|
96
141
|
|
|
97
142
|
return (
|
|
98
|
-
<View>
|
|
143
|
+
<View onLayout={onContainerLayout}>
|
|
144
|
+
{/* Hidden measurement text: only meaningful after we know container width */}
|
|
145
|
+
{containerWidth ? (
|
|
146
|
+
<Text
|
|
147
|
+
key={hiddenTextKey}
|
|
148
|
+
// make sure the hidden text has same width as container
|
|
149
|
+
style={[
|
|
150
|
+
// width must be exact to get consistent wrapping on both platforms
|
|
151
|
+
{ position: "absolute", left: 0, top: -10000, width: containerWidth, opacity: 0 },
|
|
152
|
+
textStyle as any,
|
|
153
|
+
]}
|
|
154
|
+
onTextLayout={onMeasuredTextLayout}
|
|
155
|
+
accessible={false}
|
|
156
|
+
importantForAccessibility='no-hide-descendants'
|
|
157
|
+
>
|
|
158
|
+
{formattedText}
|
|
159
|
+
</Text>
|
|
160
|
+
) : null}
|
|
161
|
+
|
|
162
|
+
{/* Visible text */}
|
|
99
163
|
<Text
|
|
100
|
-
// Use text content in the key to ensure it only re-renders when text changes
|
|
101
|
-
key={`${expanded ? "expanded" : "collapsed"}-${text}`}
|
|
102
164
|
style={textStyle}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// iOS: only measure collapsed height when not expanded.
|
|
106
|
-
onLayout={Platform.OS === "ios" && !expanded ? handleCollapsedLayout : undefined}
|
|
107
|
-
numberOfLines={expanded ? undefined : 4}
|
|
108
|
-
ellipsizeMode="tail"
|
|
165
|
+
numberOfLines={isExpanded ? undefined : collapseLines}
|
|
166
|
+
ellipsizeMode='tail'
|
|
109
167
|
>
|
|
110
168
|
{formattedText}
|
|
111
169
|
</Text>
|
|
112
170
|
|
|
113
|
-
{/*
|
|
114
|
-
{
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
{formattedText}
|
|
120
|
-
</Text>
|
|
121
|
-
)}
|
|
122
|
-
|
|
123
|
-
{/* Only show the toggle if the text was truncated in collapsed mode */}
|
|
124
|
-
{isTruncated && (
|
|
125
|
-
<View style={{ alignItems: "flex-end", marginTop: 8 }}>
|
|
126
|
-
<TouchableOpacity onPress={() => setExpanded(!expanded)}>
|
|
127
|
-
<Text style={textStyle}>
|
|
128
|
-
{expanded ? t("SHOW_LESS") : t("READ_MORE")}
|
|
171
|
+
{/* Toggle (only when truncation is needed) */}
|
|
172
|
+
{isTruncatable ? (
|
|
173
|
+
<View style={[{ alignItems: "flex-end", marginTop: 6 }, toggleContainerStyle]}>
|
|
174
|
+
<TouchableOpacity onPress={toggle} accessibilityRole='button'>
|
|
175
|
+
<Text style={[{ alignSelf: "flex-end" }, textStyle, toggleTextStyle]}>
|
|
176
|
+
{isExpanded ? t("SHOW_LESS") : t("READ_MORE")}
|
|
129
177
|
</Text>
|
|
130
178
|
</TouchableOpacity>
|
|
131
179
|
</View>
|
|
132
|
-
)}
|
|
180
|
+
) : null}
|
|
133
181
|
</View>
|
|
134
182
|
);
|
|
135
183
|
};
|
|
136
|
-
|
|
137
184
|
export default CometChatTextBubble;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type for Translation objects, each language contains key-value pairs
|
|
3
|
-
*/
|
|
4
|
-
type Translation = {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Type for translations mapping language code to Translation
|
|
9
|
-
*/
|
|
10
|
-
type Translations = {
|
|
11
|
-
[languageCode: string]: Translation;
|
|
12
|
-
};
|
|
13
|
-
declare class CometChatLocalize {
|
|
14
|
-
/**Properties and constants */
|
|
15
|
-
static fallbackLanguage: string;
|
|
16
|
-
static locale: string;
|
|
17
|
-
static rtlLanguages: string[];
|
|
18
|
-
static direction: Readonly<{
|
|
19
|
-
ltr: "ltr";
|
|
20
|
-
rtl: "rtl";
|
|
21
|
-
}>;
|
|
22
|
-
/** The translations object now has a more explicit type */
|
|
23
|
-
static translations: Translations;
|
|
24
|
-
/**
|
|
25
|
-
* Needs to be called at the start of the application in order to set the language
|
|
26
|
-
* @param {Object} - language & resources
|
|
27
|
-
*/
|
|
28
|
-
static init: ({ language, resources, }: {
|
|
29
|
-
language?: string | undefined;
|
|
30
|
-
resources?: Translations | undefined;
|
|
31
|
-
}) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Returns the native language
|
|
34
|
-
* @returns {String} native language i.e. en-US
|
|
35
|
-
*/
|
|
36
|
-
static getNativeLanguage: () => string;
|
|
37
|
-
/**
|
|
38
|
-
* Returns the language code
|
|
39
|
-
* @returns {String} language code i.e. en
|
|
40
|
-
*/
|
|
41
|
-
static getLanguageCode: () => string;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the active language. Return fallback language if translation is not available for the active language
|
|
44
|
-
* @returns {String} active language
|
|
45
|
-
*/
|
|
46
|
-
static getLocale: () => string;
|
|
47
|
-
/**
|
|
48
|
-
* Set the active language
|
|
49
|
-
* @param {String} language
|
|
50
|
-
*/
|
|
51
|
-
static setLocale: (language: string) => void;
|
|
52
|
-
/**
|
|
53
|
-
* Accepts the string to localize and return the localized string
|
|
54
|
-
* @param {String} str
|
|
55
|
-
* @returns {String} localized str
|
|
56
|
-
*/
|
|
57
|
-
static localize: (str: string) => string;
|
|
58
|
-
/**
|
|
59
|
-
* Sets the default language if no language is passed in init method
|
|
60
|
-
*/
|
|
61
|
-
static setDefaultLanguage: () => void;
|
|
62
|
-
/**
|
|
63
|
-
* Returns true if the active language is rtl otherwise return false
|
|
64
|
-
* @returns {Boolean} whether the language is rtl or not
|
|
65
|
-
*/
|
|
66
|
-
static isRTL: () => boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Returns rtl or ltr based on the active language
|
|
69
|
-
* @returns {String} the direction of the active language
|
|
70
|
-
*/
|
|
71
|
-
static getDir: () => string;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns localized string based on active language
|
|
75
|
-
* @param {String} str
|
|
76
|
-
* @returns {String} localized str
|
|
77
|
-
*/
|
|
78
|
-
declare const localize: (str: string) => string;
|
|
79
|
-
export { CometChatLocalize, localize };
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { NativeModules, Platform } from "react-native";
|
|
2
|
-
import translationAR from "./resources/ar/translation.json";
|
|
3
|
-
import translationDE from "./resources/de/translation.json";
|
|
4
|
-
import translationEN from "./resources/en/translation.json";
|
|
5
|
-
import translationES from "./resources/es/translation.json";
|
|
6
|
-
import translationFR from "./resources/fr/translation.json";
|
|
7
|
-
import translationHI from "./resources/hi/translation.json";
|
|
8
|
-
import translationHU from "./resources/hu/translation.json";
|
|
9
|
-
import translationLT from "./resources/lt/translation.json";
|
|
10
|
-
import translationMS from "./resources/ms/translation.json";
|
|
11
|
-
import translationPT from "./resources/pt/translation.json";
|
|
12
|
-
import translationRU from "./resources/ru/translation.json";
|
|
13
|
-
import translationSV from "./resources/sv/translation.json";
|
|
14
|
-
import translationZHTW from "./resources/zh-tw/translation.json";
|
|
15
|
-
import translationZH from "./resources/zh/translation.json";
|
|
16
|
-
class CometChatLocalize {
|
|
17
|
-
/**Properties and constants */
|
|
18
|
-
static fallbackLanguage = "en";
|
|
19
|
-
static locale;
|
|
20
|
-
static rtlLanguages = ["ar"];
|
|
21
|
-
static direction = Object.freeze({
|
|
22
|
-
ltr: "ltr",
|
|
23
|
-
rtl: "rtl",
|
|
24
|
-
});
|
|
25
|
-
/** The translations object now has a more explicit type */
|
|
26
|
-
static translations = {
|
|
27
|
-
ar: translationAR,
|
|
28
|
-
de: translationDE,
|
|
29
|
-
en: translationEN,
|
|
30
|
-
es: translationES,
|
|
31
|
-
fr: translationFR,
|
|
32
|
-
hi: translationHI,
|
|
33
|
-
ms: translationMS,
|
|
34
|
-
pt: translationPT,
|
|
35
|
-
ru: translationRU,
|
|
36
|
-
zh: translationZH,
|
|
37
|
-
"zh-tw": translationZHTW,
|
|
38
|
-
sv: translationSV,
|
|
39
|
-
lt: translationLT,
|
|
40
|
-
hu: translationHU,
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Needs to be called at the start of the application in order to set the language
|
|
44
|
-
* @param {Object} - language & resources
|
|
45
|
-
*/
|
|
46
|
-
static init = ({ language, resources, }) => {
|
|
47
|
-
if (language) {
|
|
48
|
-
this.locale = language;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.setDefaultLanguage();
|
|
52
|
-
}
|
|
53
|
-
/**Override resources */
|
|
54
|
-
if (resources) {
|
|
55
|
-
for (const resource in resources) {
|
|
56
|
-
/**Add to the original array of translations if language code is not found */
|
|
57
|
-
if (!this.translations[resource]) {
|
|
58
|
-
this.translations[resource] = resources[resource];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
for (const key in resources[resource]) {
|
|
62
|
-
this.translations[resource][key] = resources[resource][key];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Returns the native language
|
|
70
|
-
* @returns {String} native language i.e. en-US
|
|
71
|
-
*/
|
|
72
|
-
static getNativeLanguage = () => {
|
|
73
|
-
return Platform.OS === "ios"
|
|
74
|
-
? NativeModules.SettingsManager.settings.AppleLocale ||
|
|
75
|
-
NativeModules.SettingsManager.settings.AppleLanguages[0] //iOS 13
|
|
76
|
-
: NativeModules.I18nManager.localeIdentifier.replace("_", "-");
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Returns the language code
|
|
80
|
-
* @returns {String} language code i.e. en
|
|
81
|
-
*/
|
|
82
|
-
static getLanguageCode = () => {
|
|
83
|
-
const languageCode = this.getNativeLanguage().toLowerCase();
|
|
84
|
-
// check if the language set in the native has hyphen(-), if yes split and take the first element of the array
|
|
85
|
-
if (languageCode.indexOf("-") !== -1 && languageCode !== "zh-tw") {
|
|
86
|
-
return languageCode.split("-")[0];
|
|
87
|
-
}
|
|
88
|
-
return languageCode;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Returns the active language. Return fallback language if translation is not available for the active language
|
|
92
|
-
* @returns {String} active language
|
|
93
|
-
*/
|
|
94
|
-
static getLocale = () => {
|
|
95
|
-
let language = this.locale;
|
|
96
|
-
if (!Object.prototype.hasOwnProperty.call(this.translations, language)) {
|
|
97
|
-
language = this.fallbackLanguage;
|
|
98
|
-
}
|
|
99
|
-
return language;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Set the active language
|
|
103
|
-
* @param {String} language
|
|
104
|
-
*/
|
|
105
|
-
static setLocale = (language) => {
|
|
106
|
-
this.locale = language;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Accepts the string to localize and return the localized string
|
|
110
|
-
* @param {String} str
|
|
111
|
-
* @returns {String} localized str
|
|
112
|
-
*/
|
|
113
|
-
static localize = (str) => {
|
|
114
|
-
const language = this.getLocale();
|
|
115
|
-
return this.translations[language]?.[str] ?? str; // Fallback to the key if translation is not found
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Sets the default language if no language is passed in init method
|
|
119
|
-
*/
|
|
120
|
-
static setDefaultLanguage = () => {
|
|
121
|
-
// get the active language
|
|
122
|
-
const activeLanguage = this.getLocale();
|
|
123
|
-
// get the native language code
|
|
124
|
-
const nativeLanguageCode = this.getLanguageCode();
|
|
125
|
-
// if there is no active language or active language is different from native language, update active language with native language
|
|
126
|
-
if (!activeLanguage || activeLanguage !== nativeLanguageCode) {
|
|
127
|
-
this.setLocale(nativeLanguageCode);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Returns true if the active language is rtl otherwise return false
|
|
132
|
-
* @returns {Boolean} whether the language is rtl or not
|
|
133
|
-
*/
|
|
134
|
-
static isRTL = () => {
|
|
135
|
-
return this.rtlLanguages.includes(this.getLocale());
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Returns rtl or ltr based on the active language
|
|
139
|
-
* @returns {String} the direction of the active language
|
|
140
|
-
*/
|
|
141
|
-
static getDir = () => {
|
|
142
|
-
return this.isRTL() ? this.direction.rtl : this.direction.ltr;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns localized string based on active language
|
|
147
|
-
* @param {String} str
|
|
148
|
-
* @returns {String} localized str
|
|
149
|
-
*/
|
|
150
|
-
const localize = (str) => CometChatLocalize.localize(str);
|
|
151
|
-
export { CometChatLocalize, localize };
|
|
152
|
-
//# sourceMappingURL=CometChatLocalize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CometChatLocalize.js","sourceRoot":"","sources":["../../../../src/shared/resources/CometChatLocalize/CometChatLocalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAC5D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAY5D,MAAM,iBAAiB;IACr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