@planningcenter/chat-react-native 4.5.1-rc.0 → 4.6.0-rc.0

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.
Files changed (36) hide show
  1. package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
  2. package/build/components/conversation/attachments/giphy_attachment.js +2 -2
  3. package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
  4. package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
  5. package/build/components/conversation/attachments/image_attachment.js +5 -3
  6. package/build/components/conversation/attachments/image_attachment.js.map +1 -1
  7. package/build/components/conversation/message_form.d.ts.map +1 -1
  8. package/build/components/conversation/message_form.js +2 -2
  9. package/build/components/conversation/message_form.js.map +1 -1
  10. package/build/screens/age_check/age_check_underage_screen.d.ts.map +1 -1
  11. package/build/screens/age_check/age_check_underage_screen.js +2 -1
  12. package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
  13. package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -1
  14. package/build/screens/attachment_actions/attachment_actions_screen.js +5 -2
  15. package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -1
  16. package/build/screens/bug_report_screen.d.ts.map +1 -1
  17. package/build/screens/bug_report_screen.js +2 -2
  18. package/build/screens/bug_report_screen.js.map +1 -1
  19. package/build/screens/get_help_screen.js +2 -2
  20. package/build/screens/get_help_screen.js.map +1 -1
  21. package/build/utils/native_adapters/linking.d.ts +11 -3
  22. package/build/utils/native_adapters/linking.d.ts.map +1 -1
  23. package/build/utils/native_adapters/linking.js.map +1 -1
  24. package/package.json +2 -2
  25. package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
  26. package/src/__tests__/screens/get_help_screen.test.ts +36 -0
  27. package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
  28. package/src/components/conversation/attachments/image_attachment.tsx +2 -3
  29. package/src/components/conversation/message_form.tsx +1 -1
  30. package/src/screens/age_check/age_check_underage_screen.tsx +2 -1
  31. package/src/screens/attachment_actions/__tests__/attachment_actions_screen.test.tsx +37 -1
  32. package/src/screens/attachment_actions/attachment_actions_screen.tsx +3 -2
  33. package/src/screens/bug_report_screen.tsx +2 -10
  34. package/src/screens/get_help_screen.tsx +2 -2
  35. package/src/utils/native_adapters/__tests__/linking.test.ts +12 -0
  36. package/src/utils/native_adapters/linking.ts +12 -3
@@ -1,9 +1,17 @@
1
1
  import { HeaderHeightContext } from '@react-navigation/elements'
2
2
  import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
3
- import { render } from '@testing-library/react-native'
3
+ import { fireEvent, render } from '@testing-library/react-native'
4
4
  import React from 'react'
5
5
  import { SafeAreaProvider } from 'react-native-safe-area-context'
6
6
  import type { ConversationResource } from '../../../types'
7
+ import {
8
+ AudioAdapter,
9
+ ChatAdapters,
10
+ ClipboardAdapter,
11
+ ImagePickerAdapter,
12
+ LinkingAdapter,
13
+ VideoAdapter,
14
+ } from '../../../utils/native_adapters'
7
15
  import { AttachmentActionsScreen, AttachmentActionsScreenProps } from '../attachment_actions_screen'
8
16
 
9
17
  let mockConversation = { id: 1, disabled: false } as ConversationResource
@@ -19,6 +27,8 @@ jest.mock('../hooks/useDeleteAttachment', () => ({
19
27
  useDeleteAttachment: () => ({ handleDeleteAttachment: jest.fn() }),
20
28
  }))
21
29
 
30
+ const hostOpenURL = jest.fn(async (_url: string, _options?: object) => {})
31
+
22
32
  const safeAreaMetrics = {
23
33
  frame: { x: 0, y: 0, width: 390, height: 844 },
24
34
  insets: { top: 0, right: 0, bottom: 0, left: 0 },
@@ -51,6 +61,22 @@ const renderScreen = (params: Partial<AttachmentActionsScreenProps['route']['par
51
61
  }
52
62
 
53
63
  describe('AttachmentActionsScreen', () => {
64
+ beforeAll(() => {
65
+ ChatAdapters.configure({
66
+ clipboard: new ClipboardAdapter({
67
+ getStringAsync: async () => '',
68
+ setStringAsync: async () => {},
69
+ }),
70
+ audio: new AudioAdapter({ useAudio: () => ({}) as any }),
71
+ video: new VideoAdapter({ Player: React.forwardRef(() => null) }),
72
+ imagePicker: new ImagePickerAdapter({
73
+ openCameraAsync: async () => ({ canceled: true, assets: null }),
74
+ openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
75
+ }),
76
+ linking: new LinkingAdapter({ openURL: hostOpenURL, canOpenURL: async () => true }),
77
+ })
78
+ })
79
+
54
80
  beforeEach(() => {
55
81
  mockConversation = { id: 1, disabled: false } as ConversationResource
56
82
  })
@@ -69,4 +95,14 @@ describe('AttachmentActionsScreen', () => {
69
95
  expect(queryByText('Delete image')).toBeNull()
70
96
  expect(getByText('Open in browser')).toBeTruthy()
71
97
  })
98
+
99
+ it('asks the host app to open the attachment in the browser', () => {
100
+ const { getByText } = renderScreen()
101
+
102
+ fireEvent.press(getByText('Open in browser'))
103
+
104
+ expect(hostOpenURL).toHaveBeenCalledWith('https://example.com/a1.png', {
105
+ forceOpenInBrowser: true,
106
+ })
107
+ })
72
108
  })
@@ -1,8 +1,9 @@
1
1
  import { StaticScreenProps, useNavigation } from '@react-navigation/native'
2
2
  import React, { useCallback } from 'react'
3
- import { Alert, Linking, StyleSheet } from 'react-native'
3
+ import { Alert, StyleSheet } from 'react-native'
4
4
  import FormSheet, { getFormSheetScreenOptions } from '../../components/primitive/form_sheet'
5
5
  import { useConversation } from '../../hooks/use_conversation'
6
+ import { Linking } from '../../utils'
6
7
  import { useDeleteAttachment } from './hooks/useDeleteAttachment'
7
8
 
8
9
  export const AttachmentActionsScreenOptions = getFormSheetScreenOptions({
@@ -59,7 +60,7 @@ export function AttachmentActionsScreen({ route }: AttachmentActionsScreenProps)
59
60
  }, [attachmentName, handleDeleteAttachment, navigation])
60
61
 
61
62
  const handleOpenInBrowser = () => {
62
- Linking.openURL(attachmentUrl)
63
+ Linking.openURL(attachmentUrl, { forceOpenInBrowser: true })
63
64
  navigation.goBack()
64
65
  }
65
66
 
@@ -5,15 +5,7 @@ import type {
5
5
  } from '@react-navigation/native-stack'
6
6
  import { startsWith } from 'lodash'
7
7
  import React, { useCallback, useState } from 'react'
8
- import {
9
- View,
10
- StyleSheet,
11
- TextInput,
12
- Linking,
13
- ScrollView,
14
- TouchableOpacity,
15
- Platform,
16
- } from 'react-native'
8
+ import { View, StyleSheet, TextInput, ScrollView, TouchableOpacity, Platform } from 'react-native'
17
9
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
18
10
  import {
19
11
  Button,
@@ -38,7 +30,7 @@ import { useTheme } from '../hooks'
38
30
  import { useAppName } from '../hooks/use_app_name'
39
31
  import { useReportBugAction } from '../hooks/use_report_bug_action'
40
32
  import { useUploadClient } from '../hooks/use_upload_client'
41
- import { ImagePicker, ImagePickerResult, platformFontWeightBold } from '../utils'
33
+ import { ImagePicker, ImagePickerResult, Linking, platformFontWeightBold } from '../utils'
42
34
 
43
35
  const MAX_DESCRIPTION_LENGTH = 2000
44
36
 
@@ -1,12 +1,12 @@
1
1
  import { StaticScreenProps, useNavigation } from '@react-navigation/native'
2
2
  import { useCallback, useMemo } from 'react'
3
- import { Alert, Linking, StyleSheet, View } from 'react-native'
3
+ import { Alert, StyleSheet, View } from 'react-native'
4
4
  import { Heading, PressableRow, Text, TextInlineButton } from '../components'
5
5
  import { useApiGet, useTheme } from '../hooks'
6
6
  import { useAppName } from '../hooks/use_app_name'
7
7
  import { useOrganization } from '../hooks/use_organization'
8
8
  import { ResourceObject } from '../types'
9
- import { Clipboard } from '../utils'
9
+ import { Clipboard, Linking } from '../utils'
10
10
 
11
11
  type GetHelpScreenRouteProps = {
12
12
  type?: 'chat' | 'general'
@@ -0,0 +1,12 @@
1
+ import { LinkingAdapter } from '../linking'
2
+
3
+ describe('LinkingAdapter', () => {
4
+ it('forwards open options to the host', async () => {
5
+ const openURL = jest.fn(async () => {})
6
+ const adapter = new LinkingAdapter({ openURL, canOpenURL: async () => true })
7
+
8
+ await adapter.openURL('https://example.com', { forceOpenInBrowser: true })
9
+
10
+ expect(openURL).toHaveBeenCalledWith('https://example.com', { forceOpenInBrowser: true })
11
+ })
12
+ })
@@ -1,10 +1,19 @@
1
1
  import { Linking } from 'react-native'
2
2
 
3
- export class LinkingAdapter {
4
- openURL: Linking['openURL']
3
+ export type LinkingOpenURLOptions = {
4
+ forceOpenInBrowser?: boolean
5
+ }
6
+
7
+ type LinkingMethods = {
8
+ openURL: (url: string, options?: LinkingOpenURLOptions) => Promise<unknown>
5
9
  canOpenURL: Linking['canOpenURL']
10
+ }
11
+
12
+ export class LinkingAdapter {
13
+ openURL: LinkingMethods['openURL']
14
+ canOpenURL: LinkingMethods['canOpenURL']
6
15
 
7
- constructor(methods: Pick<Linking, 'openURL' | 'canOpenURL'>) {
16
+ constructor(methods: LinkingMethods) {
8
17
  this.openURL = methods.openURL.bind(Linking)
9
18
  this.canOpenURL = methods.canOpenURL.bind(Linking)
10
19
  }