@cactuslab/native-navigation-react
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -16,5 +16,5 @@ import type { ClickEventData, ComponentId, DismissOptions, DismissResult, NativeNavigationPlugin, TabUpdate, ViewUpdate } from '@cactuslab/native-navigation'; | ||
export declare function createReactContext(options: ContextInit): NativeNavigationContext; | ||
declare type ClickListenerFunc = (data: ClickEventData) => void; | ||
declare type ViewTransitionListenerFunc = () => void; | ||
declare type RemoveListenerFunction = () => void; | ||
type ClickListenerFunc = (data: ClickEventData) => void; | ||
type ViewTransitionListenerFunc = () => void; | ||
type RemoveListenerFunction = () => void; | ||
export interface NativeNavigationContext { | ||
@@ -21,0 +21,0 @@ /** |
@@ -5,5 +5,10 @@ import React, { useContext } from 'react'; | ||
function createPluginComponentListener(type, func) { | ||
let handle; | ||
const holder = {}; | ||
plugin.addListener(`${type}:${componentId}`, func).then(result => { | ||
handle = result; | ||
if (holder.removed) { | ||
result.remove(); | ||
} | ||
else { | ||
holder.handle = result; | ||
} | ||
}).catch(reason => { | ||
@@ -13,2 +18,3 @@ console.warn(`NativeNavigation: Failed to add ${type} listener for ${componentId}: ${reason}`); | ||
return function () { | ||
const handle = holder.handle; | ||
if (handle) { | ||
@@ -18,3 +24,3 @@ handle.remove(); | ||
else { | ||
console.warn(`NativeNavigation: Failed to remove ${type} listener for ${componentId}. This may cause a memory leak.`); | ||
holder.removed = true; | ||
} | ||
@@ -21,0 +27,0 @@ }; |
@@ -15,4 +15,4 @@ import type { ComponentId, CreateViewEventData, MessageEventData } from '@cactuslab/native-navigation'; | ||
} | ||
export declare type NativeNavigationReactRoot = React.ComponentType<NativeNavigationReactRootProps>; | ||
export type NativeNavigationReactRoot = React.ComponentType<NativeNavigationReactRootProps>; | ||
export declare function toNativeNavigationReactRootProps(data: CreateViewEventData, viewWindow: Window): NativeNavigationReactRootProps; | ||
export declare type MessageListener = (data: MessageEventData) => void; | ||
export type MessageListener = (data: MessageEventData) => void; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var nativeNavigation = require('@cactuslab/native-navigation'); | ||
@@ -9,13 +7,13 @@ var React = require('react'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM); | ||
function createReactContext(options) { | ||
const { componentId, pathname, search, hash, state, stack, viewWindow, plugin } = options; | ||
function createPluginComponentListener(type, func) { | ||
let handle; | ||
const holder = {}; | ||
plugin.addListener(`${type}:${componentId}`, func).then(result => { | ||
handle = result; | ||
if (holder.removed) { | ||
result.remove(); | ||
} | ||
else { | ||
holder.handle = result; | ||
} | ||
}).catch(reason => { | ||
@@ -25,2 +23,3 @@ console.warn(`NativeNavigation: Failed to add ${type} listener for ${componentId}: ${reason}`); | ||
return function () { | ||
const handle = holder.handle; | ||
if (handle) { | ||
@@ -30,3 +29,3 @@ handle.remove(); | ||
else { | ||
console.warn(`NativeNavigation: Failed to remove ${type} listener for ${componentId}. This may cause a memory leak.`); | ||
holder.removed = true; | ||
} | ||
@@ -144,3 +143,3 @@ }; | ||
}; | ||
const Context = React__default["default"].createContext(DEFAULT_CONTEXT); | ||
const Context = React.createContext(DEFAULT_CONTEXT); | ||
function useNativeNavigationContext() { | ||
@@ -468,3 +467,3 @@ return React.useContext(Context); | ||
views[id] = viewWindow; | ||
const reactRoot = ReactDOM__default["default"].createRoot(rootElement); | ||
const reactRoot = ReactDOM.createRoot(rootElement); | ||
reactRoots[id] = reactRoot; | ||
@@ -501,3 +500,3 @@ render(viewWindow, reactRoot, toNativeNavigationReactRootProps(data, viewWindow)); | ||
}); | ||
reactRoot.render(React__default["default"].createElement(Context.Provider, { value: context }, React__default["default"].createElement(root, props))); | ||
reactRoot.render(React.createElement(Context.Provider, { value: context }, React.createElement(root, props))); | ||
/* Wait a moment to allow the webview to render the DOM... it would be nice to find a signal we could use instead of just waiting */ | ||
@@ -504,0 +503,0 @@ setTimeout(function () { |
var CapacitorNativeNavigationReact = (function (exports, nativeNavigation, React, ReactDOM) { | ||
'use strict'; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM); | ||
function createReactContext(options) { | ||
const { componentId, pathname, search, hash, state, stack, viewWindow, plugin } = options; | ||
function createPluginComponentListener(type, func) { | ||
let handle; | ||
const holder = {}; | ||
plugin.addListener(`${type}:${componentId}`, func).then(result => { | ||
handle = result; | ||
if (holder.removed) { | ||
result.remove(); | ||
} | ||
else { | ||
holder.handle = result; | ||
} | ||
}).catch(reason => { | ||
@@ -19,2 +19,3 @@ console.warn(`NativeNavigation: Failed to add ${type} listener for ${componentId}: ${reason}`); | ||
return function () { | ||
const handle = holder.handle; | ||
if (handle) { | ||
@@ -24,3 +25,3 @@ handle.remove(); | ||
else { | ||
console.warn(`NativeNavigation: Failed to remove ${type} listener for ${componentId}. This may cause a memory leak.`); | ||
holder.removed = true; | ||
} | ||
@@ -138,3 +139,3 @@ }; | ||
}; | ||
const Context = React__default["default"].createContext(DEFAULT_CONTEXT); | ||
const Context = React.createContext(DEFAULT_CONTEXT); | ||
function useNativeNavigationContext() { | ||
@@ -462,3 +463,3 @@ return React.useContext(Context); | ||
views[id] = viewWindow; | ||
const reactRoot = ReactDOM__default["default"].createRoot(rootElement); | ||
const reactRoot = ReactDOM.createRoot(rootElement); | ||
reactRoots[id] = reactRoot; | ||
@@ -495,3 +496,3 @@ render(viewWindow, reactRoot, toNativeNavigationReactRootProps(data, viewWindow)); | ||
}); | ||
reactRoot.render(React__default["default"].createElement(Context.Provider, { value: context }, React__default["default"].createElement(root, props))); | ||
reactRoot.render(React.createElement(Context.Provider, { value: context }, React.createElement(root, props))); | ||
/* Wait a moment to allow the webview to render the DOM... it would be nice to find a signal we could use instead of just waiting */ | ||
@@ -526,4 +527,2 @@ setTimeout(function () { | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return exports; | ||
@@ -530,0 +529,0 @@ |
{ | ||
"name": "@cactuslab/native-navigation-react", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "React support for Native navigation for Capacitor apps", | ||
@@ -30,16 +30,16 @@ "main": "dist/plugin.cjs.js", | ||
"devDependencies": { | ||
"@cactuslab/native-navigation": "^0.2.0", | ||
"@capacitor/core": "^4.0.0", | ||
"@cactuslab/native-navigation": "^0.3.0", | ||
"@capacitor/core": "^4.8.0", | ||
"@ionic/eslint-config": "^0.3.0", | ||
"@ionic/prettier-config": "^1.0.1", | ||
"@types/react": "^18.0.24", | ||
"@types/react-dom": "^18.0.8", | ||
"eslint": "^7.11.0", | ||
"prettier": "~2.3.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.32.0", | ||
"typescript": "~4.8.4" | ||
"@ionic/prettier-config": "^2.1.2", | ||
"@types/react": "^18.2.0", | ||
"@types/react-dom": "^18.2.1", | ||
"eslint": "^8.39.0", | ||
"prettier": "~2.8.8", | ||
"rimraf": "^5.0.0", | ||
"rollup": "^3.21.3", | ||
"typescript": "~5.0.4" | ||
}, | ||
"peerDependencies": { | ||
"@cactuslab/native-navigation": "^0.2.0", | ||
"@cactuslab/native-navigation": "^0.3.0", | ||
"@capacitor/core": "^4.0.0", | ||
@@ -58,3 +58,3 @@ "react": "^18.2.0", | ||
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"", | ||
"build": "pnpm run clean && tsc && rollup -c rollup.config.js", | ||
"build": "pnpm run clean && tsc && rollup -c rollup.config.mjs", | ||
"clean": "rimraf ./dist", | ||
@@ -61,0 +61,0 @@ "watch": "tsc --watch" |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1670
177146