Skip to content

Commit

Permalink
links - open on browser (#980)
Browse files Browse the repository at this point in the history
* expo link

* preview profile

* bump eas-cli

* chore(release): 0.10.10

* added intent filters

* added intent filters

* update

* update

* chore(release): 0.10.11

* update

* added intent

* revert changes

* space

* space

revert changes

added intent

update

chore(release): 0.10.11

update

* update comment
  • Loading branch information
thedoublejay authored Sep 30, 2021
1 parent dacfae2 commit e267547
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
14 changes: 14 additions & 0 deletions mobile-app/app/api/linking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Platform } from 'react-native'
import * as Linking from 'expo-linking'
import * as WebBrowser from 'expo-web-browser'

export async function openURL (url: string): Promise<void> {
if (Platform.OS !== 'android') {
const supported = await Linking.canOpenURL(url)
if (supported) {
await Linking.openURL(url)
return
}
}
await WebBrowser.openBrowserAsync(url)
}
8 changes: 3 additions & 5 deletions mobile-app/app/components/OceanInterface/OceanInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import { firstTransactionSelector, ocean, OceanTransaction } from '@store/ocean'
import { tailwind } from '@tailwind'
import { translate } from '@translations'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { Animated, Linking, TouchableOpacity, View } from 'react-native'
import { Animated, TouchableOpacity, View } from 'react-native'
import { useDispatch, useSelector } from 'react-redux'
import { ThemedActivityIndicator, ThemedIcon, ThemedText } from '../themed'
import { openURL } from '@api/linking'

const MAX_AUTO_RETRY = 1
const MAX_TIMEOUT = 300000
Expand All @@ -24,10 +25,7 @@ const INTERVAL_TIME = 5000
async function gotoExplorer (txUrl: string): Promise<void> {
// TODO(thedoublejay) explorer URL
// TODO (future improvement): this page should support in mempool, to be confirm
const supported = await Linking.canOpenURL(txUrl)
if (supported) {
await Linking.openURL(txUrl)
}
await openURL(txUrl)
}

async function broadcastTransaction (tx: CTransactionSegWit, client: WhaleApiClient, retries: number = 0): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { MaterialCommunityIcons } from '@expo/vector-icons'
import { nativeApplicationVersion } from 'expo-application'
import React from 'react'
import { Linking, TouchableOpacity, View } from 'react-native'
import { TouchableOpacity, View } from 'react-native'
import { AppIcon } from '@components/icons/AppIcon'
import { ThemedIcon, ThemedScrollView, ThemedText, ThemedTouchableOpacity } from '@components/themed'
import { tailwind } from '@tailwind'
import { translate } from '@translations'
import { useNavigation } from '@react-navigation/native'
import { openURL } from '@api/linking'

interface AboutScreenLinks {
testID: string
Expand Down Expand Up @@ -169,13 +170,6 @@ export function AboutScreen (): JSX.Element {
)
}

async function openURL (url: string): Promise<void> {
const supported = await Linking.canOpenURL(url)
if (supported) {
await Linking.openURL(url)
}
}

function LinkItemRow ({
title,
subtitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MaterialCommunityIcons } from '@expo/vector-icons'
import * as React from 'react'
import { useCallback } from 'react'
import { Linking, View } from 'react-native'
import { View } from 'react-native'
import {
ThemedFlatList,
ThemedIcon,
Expand All @@ -12,6 +11,7 @@ import {
} from '@components/themed'
import { tailwind } from '@tailwind'
import { translate } from '@translations'
import { openURL } from '@api/linking'

export function CommunityScreen (): JSX.Element {
return (
Expand Down Expand Up @@ -95,12 +95,9 @@ function CommunityItemRow ({
url,
icon
}: CommunityItem): JSX.Element {
const handlePress = useCallback(async () => {
const supported = await Linking.canOpenURL(url)
if (supported) {
await Linking.openURL(url)
}
}, [url])
const handlePress = async (): Promise<void> => {
await openURL(url)
}

return (
<ThemedTouchableOpacity
Expand Down

0 comments on commit e267547

Please sign in to comment.