Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nandorojo/solito
Browse files Browse the repository at this point in the history
  • Loading branch information
nandorojo committed Dec 11, 2022
2 parents 1c8f71d + 31e5f12 commit 54aa50e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/docs/guides/expo-router.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Expo Router

Expo recently announced an experimental new routing system which lets you use file-system based routing in native apps. The API is very Next.js- and Remix-esque. I view it as the future of cross-platform routing.

To use Solito with [Expo Router](https://expo.github.io/router/), you'll need to follow their [Getting Started](https://expo.github.io/router/docs/intro#getting-started) guide. These steps should be done inside of `apps/expo` in your Solito project.
To use Solito with [Expo Router](https://expo.github.io/router/), you'll need to follow their [Getting Started](https://expo.github.io/router/docs/#getting-started) guide. These steps should be done inside of `apps/expo` in your Solito project.

Once those steps are done, you're good to go. You can create files inside of `apps/expo/app` to use file system routing on iOS and Android. Solito's `useLink` hook and `Link` component will work like always.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function Home() {
const router = useRouter()

const openArtists = () => {
replace('/artists', undefined, {
router.replace('/artists', undefined, {
experimental: {
nativeBehavior: 'stack-replace',
isNestedNavigator: true,
Expand Down
19 changes: 18 additions & 1 deletion src/link/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import type { ComponentProps, ComponentType } from 'react'
import { Platform } from 'react-native'

import { openURL } from './linking'
import { NextLink } from './next-link'
import { useLink } from './use-custom-link'

Expand Down Expand Up @@ -65,12 +66,28 @@ function LinkCore({
{...componentProps}
onPress={(e?: any) => {
componentProps?.onPress?.(e)
linkTo.onPress(e)
const link = as || href
// Handles external URLs
if (
!e?.defaultPrevented &&
typeof link === 'string' &&
isAbsoluteUrl(link)
) {
openURL(link)
} else {
linkTo.onPress(e)
}
}}
>
{children}
</Component>
)
}

// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/
// Source - https://github.com/vercel/next.js/blob/77b5f79a4dff453abb62346bf75b14d859539b81/packages/next/shared/lib/utils.ts#L313
const isAbsoluteUrl = (url: string) => ABSOLUTE_URL_REGEX.test(url)

export { LinkCore }
3 changes: 3 additions & 0 deletions src/link/linking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Linking } from 'react-native'

export const openURL = (url: string) => Linking.openURL(url)
2 changes: 2 additions & 0 deletions src/link/linking.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// noop, not supported on web
export const openURL = (url: string) => {}

2 comments on commit 54aa50e

@vercel
Copy link

@vercel vercel bot commented on 54aa50e Dec 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solito-s9oj – ./example-monorepos/with-tailwind/apps/next

solito-s9oj.vercel.app
solito-s9oj-beat-gig.vercel.app
solito-s9oj-git-master-beat-gig.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 54aa50e Dec 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

with-custom-fonts – ./example-monorepos/with-custom-font/apps/next

with-custom-fonts.vercel.app
with-custom-fonts-git-master-fernandorojo.vercel.app
custom-font.example.solito.dev
with-custom-fonts-fernandorojo.vercel.app

Please sign in to comment.