Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expo-linking

Package Overview
Dependencies
Maintainers
25
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-linking - npm Package Compare versions

Comparing version 6.3.2-canary-20240628-1ba8152 to 6.4.0-canary-20240719-83ee47b

android/build.gradle

11

build/ExpoLinking.d.ts

@@ -1,3 +0,10 @@

import { Linking } from 'react-native';
export default Linking;
import { NativeModule } from 'expo-modules-core';
type ExppLinkingModuleEvents = {
onURLReceived(url: string): void;
};
declare class ExpoLinkingNativeModule extends NativeModule<ExppLinkingModuleEvents> {
getLinkingURL(): string | null;
}
declare const ExpoLinking: ExpoLinkingNativeModule;
export default ExpoLinking;
//# sourceMappingURL=ExpoLinking.d.ts.map

5

build/ExpoLinking.js

@@ -1,3 +0,4 @@

import { Linking } from 'react-native';
export default Linking;
import { requireNativeModule, NativeModule } from 'expo-modules-core';
const ExpoLinking = requireNativeModule('ExpoLinking');
export default ExpoLinking;
//# sourceMappingURL=ExpoLinking.js.map
import { URLListener } from './Linking.types';
declare const _default: {
addEventListener(type: 'url', listener: URLListener): {
addListener(eventName: any, listener: URLListener): {
remove(): void;
};
removeEventListener(type: 'url', listener: URLListener): void;
canOpenURL(): Promise<boolean>;
getInitialURL(): Promise<string>;
openURL(url: string): Promise<void>;
getLinkingURL(): string;
};
export default _default;
//# sourceMappingURL=ExpoLinking.web.d.ts.map
import invariant from 'invariant';
const listeners = [];
export default {
addEventListener(type, listener) {
addListener(eventName, listener) {
invariant(eventName === 'onURLReceived', `Linking.addListener(): ${eventName} is not a valid event`);
// Do nothing in Node.js environments

@@ -9,29 +9,11 @@ if (typeof window === 'undefined') {

}
invariant(type === 'url', `Linking.addEventListener(): ${type} is not a valid event`);
const nativeListener = (nativeEvent) => listener({ url: window.location.href, nativeEvent });
listeners.push({ listener, nativeListener });
window.addEventListener('message', nativeListener, false);
return {
remove: () => {
this.removeEventListener(type, listener);
window.removeEventListener('message', nativeListener);
},
};
},
removeEventListener(type, listener) {
// Do nothing in Node.js environments
if (typeof window === 'undefined') {
return;
}
invariant(type === 'url', `Linking.addEventListener(): ${type} is not a valid event`);
const listenerIndex = listeners.findIndex((pair) => pair.listener === listener);
invariant(listenerIndex !== -1, 'Linking.removeEventListener(): cannot remove an unregistered event listener.');
const nativeListener = listeners[listenerIndex].nativeListener;
window.removeEventListener('message', nativeListener, false);
listeners.splice(listenerIndex, 1);
},
async canOpenURL() {
// In reality this should be able to return false for links like `chrome://` on chrome.
return true;
},
async getInitialURL() {
getLinkingURL() {
if (typeof window === 'undefined')

@@ -41,9 +23,3 @@ return '';

},
async openURL(url) {
if (typeof window !== 'undefined') {
// @ts-ignore
window.location = new URL(url, window.location).toString();
}
},
};
//# sourceMappingURL=ExpoLinking.web.js.map

@@ -38,2 +38,7 @@ import { EmitterSubscription } from 'react-native';

/**
* Get the URL that was used to launch the app if it was launched by a link.
* @return The URL string that launched your app, or `null`.
*/
export declare function getLinkingURL(): string | null;
/**
* Attempt to open the given URL with an installed app. See the [Linking guide](/guides/linking)

@@ -63,2 +68,8 @@ * for more information.

export declare function useURL(): string | null;
/**
* Returns the linking URL followed by any subsequent changes to the URL.
* Always returns the initial URL immediately on reload.
* @return Returns the initial URL or `null`.
*/
export declare function useLinkingURL(): string | null;
export * from './Linking.types';

@@ -65,0 +76,0 @@ export * from './Schemes';

import { UnavailabilityError } from 'expo-modules-core';
import { useEffect, useState } from 'react';
import { Platform } from 'react-native';
import NativeLinking from './ExpoLinking';
import ExpoLinking from './ExpoLinking';
import RNLinking from './RNLinking';
import { parse } from './createURL';

@@ -18,3 +19,3 @@ import { validateURL } from './validateURL';

export function addEventListener(type, handler) {
return NativeLinking.addEventListener(type, handler);
return RNLinking.addEventListener(type, handler);
}

@@ -30,3 +31,3 @@ // @needsAudit

export async function parseInitialURLAsync() {
const initialUrl = await NativeLinking.getInitialURL();
const initialUrl = await RNLinking.getInitialURL();
if (!initialUrl) {

@@ -51,3 +52,3 @@ return {

if (Platform.OS === 'android') {
return await NativeLinking.sendIntent(action, extras);
return await RNLinking.sendIntent(action, extras);
}

@@ -64,4 +65,4 @@ throw new UnavailabilityError('Linking', 'sendIntent');

}
if (NativeLinking.openSettings) {
return await NativeLinking.openSettings();
if (RNLinking.openSettings) {
return await RNLinking.openSettings();
}

@@ -76,4 +77,11 @@ await openURL('app-settings:');

export async function getInitialURL() {
return (await NativeLinking.getInitialURL()) ?? null;
return (await RNLinking.getInitialURL()) ?? null;
}
/**
* Get the URL that was used to launch the app if it was launched by a link.
* @return The URL string that launched your app, or `null`.
*/
export function getLinkingURL() {
return ExpoLinking.getLinkingURL();
}
// @needsAudit

@@ -90,3 +98,3 @@ /**

validateURL(url);
return await NativeLinking.openURL(url);
return await RNLinking.openURL(url);
}

@@ -106,3 +114,3 @@ // @needsAudit

validateURL(url);
return await NativeLinking.canOpenURL(url);
return await RNLinking.canOpenURL(url);
}

@@ -126,2 +134,18 @@ // @needsAudit

}
/**
* Returns the linking URL followed by any subsequent changes to the URL.
* Always returns the initial URL immediately on reload.
* @return Returns the initial URL or `null`.
*/
export function useLinkingURL() {
const [url, setLink] = useState(ExpoLinking.getLinkingURL);
function onChange(event) {
setLink(event.url);
}
useEffect(() => {
const subscription = ExpoLinking.addListener('onURLReceived', onChange);
return () => subscription.remove();
}, []);
return url ?? null;
}
export * from './Linking.types';

@@ -128,0 +152,0 @@ export * from './Schemes';

@@ -9,4 +9,8 @@ # Changelog

- Add native `getLinkingURL` function. ([#29405](https://github.com/expo/expo/pull/29405) by [@aleqsio](https://github.com/aleqsio))
### 🐛 Bug fixes
- Add missing `react` and `react-native` peer dependencies for isolated modules. ([#30473](https://github.com/expo/expo/pull/30473) by [@byCedric](https://github.com/byCedric))
### 💡 Others

@@ -13,0 +17,0 @@

{
"name": "expo-linking",
"version": "6.3.2-canary-20240628-1ba8152",
"version": "6.4.0-canary-20240719-83ee47b",
"description": "Create and open deep links universally",

@@ -33,12 +33,16 @@ "main": "build/Linking.js",

"dependencies": {
"expo-constants": "16.0.3-canary-20240628-1ba8152",
"expo-constants": "16.0.3-canary-20240719-83ee47b",
"invariant": "^2.2.4"
},
"devDependencies": {
"expo-module-scripts": "3.6.0-canary-20240628-1ba8152"
"expo-module-scripts": "3.6.0-canary-20240719-83ee47b"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"jest": {
"preset": "expo-module-scripts"
},
"gitHead": "1ba815237ed606c5ee8488f68e49773fc9735cc3"
"gitHead": "83ee47b5c89c7f1b1a5101189580eaf3555f5962"
}

@@ -1,2 +0,12 @@

import { Linking } from 'react-native';
export default Linking;
import { requireNativeModule, NativeModule } from 'expo-modules-core';
type ExppLinkingModuleEvents = {
onURLReceived(url: string): void;
};
declare class ExpoLinkingNativeModule extends NativeModule<ExppLinkingModuleEvents> {
getLinkingURL(): string | null;
}
const ExpoLinking = requireNativeModule<ExpoLinkingNativeModule>('ExpoLinking');
export default ExpoLinking;
import invariant from 'invariant';
import { NativeURLListener, URLListener } from './Linking.types';
import { URLListener } from './Linking.types';
const listeners: { listener: URLListener; nativeListener: NativeURLListener }[] = [];
export default {
addEventListener(type: 'url', listener: URLListener): { remove(): void } {
addListener(eventName, listener: URLListener): { remove(): void } {
invariant(
eventName === 'onURLReceived',
`Linking.addListener(): ${eventName} is not a valid event`
);
// Do nothing in Node.js environments

@@ -14,10 +16,7 @@ if (typeof window === 'undefined') {

invariant(type === 'url', `Linking.addEventListener(): ${type} is not a valid event`);
const nativeListener: NativeURLListener = (nativeEvent) =>
listener({ url: window.location.href, nativeEvent });
listeners.push({ listener, nativeListener });
const nativeListener = (nativeEvent) => listener({ url: window.location.href, nativeEvent });
window.addEventListener('message', nativeListener, false);
return {
remove: () => {
this.removeEventListener(type, listener);
window.removeEventListener('message', nativeListener);
},

@@ -27,34 +26,6 @@ };

removeEventListener(type: 'url', listener: URLListener): void {
// Do nothing in Node.js environments
if (typeof window === 'undefined') {
return;
}
invariant(type === 'url', `Linking.addEventListener(): ${type} is not a valid event`);
const listenerIndex = listeners.findIndex((pair) => pair.listener === listener);
invariant(
listenerIndex !== -1,
'Linking.removeEventListener(): cannot remove an unregistered event listener.'
);
const nativeListener = listeners[listenerIndex].nativeListener;
window.removeEventListener('message', nativeListener, false);
listeners.splice(listenerIndex, 1);
},
async canOpenURL(): Promise<boolean> {
// In reality this should be able to return false for links like `chrome://` on chrome.
return true;
},
async getInitialURL(): Promise<string> {
getLinkingURL(): string {
if (typeof window === 'undefined') return '';
return window.location.href;
},
async openURL(url: string): Promise<void> {
if (typeof window !== 'undefined') {
// @ts-ignore
window.location = new URL(url, window.location).toString();
}
},
};

@@ -5,4 +5,5 @@ import { UnavailabilityError } from 'expo-modules-core';

import NativeLinking from './ExpoLinking';
import ExpoLinking from './ExpoLinking';
import { ParsedURL, SendIntentExtras, URLListener } from './Linking.types';
import RNLinking from './RNLinking';
import { parse } from './createURL';

@@ -22,3 +23,3 @@ import { validateURL } from './validateURL';

export function addEventListener(type: 'url', handler: URLListener): EmitterSubscription {
return NativeLinking.addEventListener(type, handler);
return RNLinking.addEventListener(type, handler);
}

@@ -35,3 +36,3 @@

export async function parseInitialURLAsync(): Promise<ParsedURL> {
const initialUrl = await NativeLinking.getInitialURL();
const initialUrl = await RNLinking.getInitialURL();
if (!initialUrl) {

@@ -58,3 +59,3 @@ return {

if (Platform.OS === 'android') {
return await NativeLinking.sendIntent(action, extras);
return await RNLinking.sendIntent(action, extras);
}

@@ -72,4 +73,4 @@ throw new UnavailabilityError('Linking', 'sendIntent');

}
if (NativeLinking.openSettings) {
return await NativeLinking.openSettings();
if (RNLinking.openSettings) {
return await RNLinking.openSettings();
}

@@ -85,5 +86,13 @@ await openURL('app-settings:');

export async function getInitialURL(): Promise<string | null> {
return (await NativeLinking.getInitialURL()) ?? null;
return (await RNLinking.getInitialURL()) ?? null;
}
/**
* Get the URL that was used to launch the app if it was launched by a link.
* @return The URL string that launched your app, or `null`.
*/
export function getLinkingURL(): string | null {
return ExpoLinking.getLinkingURL();
}
// @needsAudit

@@ -100,3 +109,3 @@ /**

validateURL(url);
return await NativeLinking.openURL(url);
return await RNLinking.openURL(url);
}

@@ -117,3 +126,3 @@

validateURL(url);
return await NativeLinking.canOpenURL(url);
return await RNLinking.canOpenURL(url);
}

@@ -142,4 +151,24 @@

/**
* Returns the linking URL followed by any subsequent changes to the URL.
* Always returns the initial URL immediately on reload.
* @return Returns the initial URL or `null`.
*/
export function useLinkingURL(): string | null {
const [url, setLink] = useState<string | null>(ExpoLinking.getLinkingURL);
function onChange(event: { url: string }) {
setLink(event.url);
}
useEffect(() => {
const subscription = ExpoLinking.addListener('onURLReceived', onChange as any);
return () => subscription.remove();
}, []);
return url ?? null;
}
export * from './Linking.types';
export * from './Schemes';
export { parse, createURL } from './createURL';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc