@jobber/components-native 0.45.0 → 0.45.1
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/dist/package.json +2 -2
- package/dist/src/AutoLink/components/ComposeTextWithLinks/ComposeTextWithLinks.js +3 -3
- package/dist/src/AutoLink/utils.js +14 -3
- package/dist/src/hooks/useAtlantisI18n/locales/en.json +4 -0
- package/dist/src/hooks/useAtlantisI18n/locales/es.json +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/AutoLink/utils.d.ts +2 -2
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.d.ts +2 -1
- package/package.json +2 -2
- package/src/AutoLink/AutoLink.test.tsx +3 -4
- package/src/AutoLink/components/ComposeTextWithLinks/ComposeTextWithLinks.tsx +3 -3
- package/src/AutoLink/utils.ts +16 -5
- package/src/hooks/useAtlantisI18n/locales/en.json +4 -0
- package/src/hooks/useAtlantisI18n/locales/es.json +4 -0
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.ts +3 -4
- package/dist/src/AutoLink/messages.js +0 -18
- package/dist/types/src/AutoLink/messages.d.ts +0 -17
- package/src/AutoLink/messages.ts +0 -19
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Match } from "autolinker";
|
|
2
|
-
import {
|
|
2
|
+
import { useAtlantisI18nValue } from "../hooks/useAtlantisI18n";
|
|
3
3
|
export declare function shouldIgnoreURL(text: string, match: Match): boolean;
|
|
4
4
|
export declare function getUrl(match: Match, immediateOpen?: boolean): string;
|
|
5
|
-
export declare function onLongPressLink(match: Match, bottomTabsVisible: boolean,
|
|
5
|
+
export declare function onLongPressLink(match: Match, bottomTabsVisible: boolean, t: useAtlantisI18nValue["t"]): void;
|
|
6
6
|
export declare function onPressLink(match: Match): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import en from "./locales/en.json";
|
|
2
|
+
export type I18nKeys = keyof typeof en;
|
|
2
3
|
export interface useAtlantisI18nValue {
|
|
3
4
|
readonly locale: string;
|
|
4
|
-
readonly t: (message:
|
|
5
|
+
readonly t: (message: I18nKeys, values?: Record<string, string>) => string;
|
|
5
6
|
}
|
|
6
7
|
export declare function useAtlantisI18n(): useAtlantisI18nValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react-native-reanimated": "^2.17.0",
|
|
85
85
|
"react-native-safe-area-context": "^4.5.2"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "8764198c93cfc2812f504b6f6509595ad6b3195c"
|
|
88
88
|
}
|
|
@@ -2,7 +2,6 @@ import React from "react";
|
|
|
2
2
|
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
3
|
import { copyTextToClipboard } from "./clipboard";
|
|
4
4
|
import { AutoLink } from "./AutoLink";
|
|
5
|
-
import { messages } from "./messages";
|
|
6
5
|
|
|
7
6
|
const mockOpenUrl = jest.fn();
|
|
8
7
|
jest.mock("react-native/Libraries/Linking/Linking", () => ({
|
|
@@ -48,7 +47,7 @@ describe("AutoLink", () => {
|
|
|
48
47
|
fireEvent(getByText(linkText), "onLongPress");
|
|
49
48
|
|
|
50
49
|
const expectedToastConfig = {
|
|
51
|
-
message:
|
|
50
|
+
message: "URL copied",
|
|
52
51
|
bottomTabsVisible: true,
|
|
53
52
|
};
|
|
54
53
|
expect(copyTextToClipboard).toHaveBeenCalledWith(
|
|
@@ -104,7 +103,7 @@ describe("AutoLink", () => {
|
|
|
104
103
|
fireEvent(getByText(emailText), "onLongPress");
|
|
105
104
|
|
|
106
105
|
const expectedToastConfig = {
|
|
107
|
-
message:
|
|
106
|
+
message: "Email copied",
|
|
108
107
|
bottomTabsVisible: true,
|
|
109
108
|
};
|
|
110
109
|
expect(copyTextToClipboard).toHaveBeenCalledWith(
|
|
@@ -158,7 +157,7 @@ describe("AutoLink", () => {
|
|
|
158
157
|
fireEvent(getByText(phoneText), "onLongPress");
|
|
159
158
|
|
|
160
159
|
const expectedToastConfig = {
|
|
161
|
-
message:
|
|
160
|
+
message: "Phone number copied",
|
|
162
161
|
bottomTabsVisible: true,
|
|
163
162
|
};
|
|
164
163
|
expect(copyTextToClipboard).toHaveBeenCalledWith(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { useIntl } from "react-intl";
|
|
3
2
|
import { Platform } from "react-native";
|
|
4
3
|
import { ComposeTextWithLinksProps } from "../../types";
|
|
5
4
|
import { onLongPressLink, onPressLink } from "../../utils";
|
|
6
5
|
import { Link } from "../Link/Link";
|
|
7
6
|
import { Text } from "../../../Text";
|
|
7
|
+
import { useAtlantisI18n } from "../../../hooks/useAtlantisI18n";
|
|
8
8
|
|
|
9
9
|
export function ComposeTextWithLinks({
|
|
10
10
|
part,
|
|
@@ -13,7 +13,7 @@ export function ComposeTextWithLinks({
|
|
|
13
13
|
bottomTabsVisible,
|
|
14
14
|
selectable = true,
|
|
15
15
|
}: ComposeTextWithLinksProps): JSX.Element {
|
|
16
|
-
const {
|
|
16
|
+
const { t } = useAtlantisI18n();
|
|
17
17
|
|
|
18
18
|
const isLink = match?.getType();
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ export function ComposeTextWithLinks({
|
|
|
26
26
|
if (selectable && Platform.OS === "android") {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
onLongPressLink(match, bottomTabsVisible,
|
|
29
|
+
onLongPressLink(match, bottomTabsVisible, t);
|
|
30
30
|
}}
|
|
31
31
|
>
|
|
32
32
|
{match.getAnchorText()}
|
package/src/AutoLink/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { EmailMatch, Match, PhoneMatch } from "autolinker";
|
|
2
|
-
import { MessageDescriptor } from "react-intl";
|
|
3
2
|
import { Linking } from "react-native";
|
|
4
|
-
import { messages } from "./messages";
|
|
5
|
-
import { LinkType } from "./types";
|
|
6
3
|
import { copyTextToClipboard } from "./clipboard";
|
|
4
|
+
import { I18nKeys, useAtlantisI18nValue } from "../hooks/useAtlantisI18n";
|
|
7
5
|
|
|
8
6
|
function hasPrefix(text: string, prefixes: string[]): boolean {
|
|
9
7
|
return prefixes.some(prefix => text.includes(prefix));
|
|
@@ -46,12 +44,12 @@ export function getUrl(match: Match, immediateOpen = true): string {
|
|
|
46
44
|
export function onLongPressLink(
|
|
47
45
|
match: Match,
|
|
48
46
|
bottomTabsVisible: boolean,
|
|
49
|
-
|
|
47
|
+
t: useAtlantisI18nValue["t"],
|
|
50
48
|
): void {
|
|
51
49
|
const linkUrl = getUrl(match, false);
|
|
52
50
|
|
|
53
51
|
const toastConfig = {
|
|
54
|
-
message:
|
|
52
|
+
message: t(getMessageKey(match)),
|
|
55
53
|
bottomTabsVisible,
|
|
56
54
|
};
|
|
57
55
|
copyTextToClipboard(linkUrl, toastConfig);
|
|
@@ -61,3 +59,16 @@ export function onPressLink(match: Match): void {
|
|
|
61
59
|
const linkUrl = getUrl(match);
|
|
62
60
|
Linking.openURL(linkUrl);
|
|
63
61
|
}
|
|
62
|
+
|
|
63
|
+
function getMessageKey(match: Match): I18nKeys {
|
|
64
|
+
switch (match.getType()) {
|
|
65
|
+
case "email":
|
|
66
|
+
return "AutoLink.emailCopied";
|
|
67
|
+
case "phone":
|
|
68
|
+
return "AutoLink.phoneCopied";
|
|
69
|
+
case "url":
|
|
70
|
+
return "AutoLink.urlCopied";
|
|
71
|
+
default:
|
|
72
|
+
return "copied";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
+
"AutoLink.emailCopied": "Correo electrónico copiado",
|
|
3
|
+
"AutoLink.phoneCopied": "Número de teléfono copiado",
|
|
4
|
+
"AutoLink.urlCopied": "URL copiada",
|
|
2
5
|
"cancel": "Cancelar",
|
|
3
6
|
"confirm": "Confirmar",
|
|
7
|
+
"copied": "Copiado",
|
|
4
8
|
"date": "Fecha",
|
|
5
9
|
"dismiss": "Descartar",
|
|
6
10
|
"done": "Listo",
|
|
@@ -2,12 +2,11 @@ import en from "./locales/en.json";
|
|
|
2
2
|
import es from "./locales/es.json";
|
|
3
3
|
import { useAtlantisContext } from "../../AtlantisContext";
|
|
4
4
|
|
|
5
|
+
export type I18nKeys = keyof typeof en;
|
|
6
|
+
|
|
5
7
|
export interface useAtlantisI18nValue {
|
|
6
8
|
readonly locale: string;
|
|
7
|
-
readonly t: (
|
|
8
|
-
message: keyof typeof en,
|
|
9
|
-
values?: Record<string, string>,
|
|
10
|
-
) => string;
|
|
9
|
+
readonly t: (message: I18nKeys, values?: Record<string, string>) => string;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export function useAtlantisI18n(): useAtlantisI18nValue {
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineMessages } from "react-intl";
|
|
2
|
-
export const messages = defineMessages({
|
|
3
|
-
phoneCopied: {
|
|
4
|
-
id: "phoneCopied",
|
|
5
|
-
defaultMessage: "Phone number copied",
|
|
6
|
-
description: "Message shown after copying a phone number",
|
|
7
|
-
},
|
|
8
|
-
emailCopied: {
|
|
9
|
-
id: "emailCopied",
|
|
10
|
-
defaultMessage: "Email copied",
|
|
11
|
-
description: "Message shown after copying an email",
|
|
12
|
-
},
|
|
13
|
-
urlCopied: {
|
|
14
|
-
id: "urlCopied",
|
|
15
|
-
defaultMessage: "URL copied",
|
|
16
|
-
description: "Message shown after copying a URL",
|
|
17
|
-
},
|
|
18
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const messages: {
|
|
2
|
-
phoneCopied: {
|
|
3
|
-
id: string;
|
|
4
|
-
defaultMessage: string;
|
|
5
|
-
description: string;
|
|
6
|
-
};
|
|
7
|
-
emailCopied: {
|
|
8
|
-
id: string;
|
|
9
|
-
defaultMessage: string;
|
|
10
|
-
description: string;
|
|
11
|
-
};
|
|
12
|
-
urlCopied: {
|
|
13
|
-
id: string;
|
|
14
|
-
defaultMessage: string;
|
|
15
|
-
description: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
package/src/AutoLink/messages.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { defineMessages } from "react-intl";
|
|
2
|
-
|
|
3
|
-
export const messages = defineMessages({
|
|
4
|
-
phoneCopied: {
|
|
5
|
-
id: "phoneCopied",
|
|
6
|
-
defaultMessage: "Phone number copied",
|
|
7
|
-
description: "Message shown after copying a phone number",
|
|
8
|
-
},
|
|
9
|
-
emailCopied: {
|
|
10
|
-
id: "emailCopied",
|
|
11
|
-
defaultMessage: "Email copied",
|
|
12
|
-
description: "Message shown after copying an email",
|
|
13
|
-
},
|
|
14
|
-
urlCopied: {
|
|
15
|
-
id: "urlCopied",
|
|
16
|
-
defaultMessage: "URL copied",
|
|
17
|
-
description: "Message shown after copying a URL",
|
|
18
|
-
},
|
|
19
|
-
});
|