Skip to content

Commit 3fd62e5

Browse files
Juan Pablo GarciaJuan Pablo Garcia
authored andcommitted
feat(helpers): deprecate methods from useNavigation hook
Deprecate setRoot from useNavigation hook Deprecate showModal from useNavigation hook Deprecate showOverlay from useNavigation hook Deprecate setDefaultOptions from useNavigation hook Deprecate dismissAllModals from useNavigation hook Deprecate getLaunchArgs from useNavigation hook fix #55
1 parent 61838b5 commit 3fd62e5

File tree

5 files changed

+91
-48
lines changed

5 files changed

+91
-48
lines changed

src/helpers/createNavigationCommands.ts

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { Layout, LayoutRoot, Navigation, Options } from 'react-native-navigation'
1+
import { Layout, Navigation, Options } from 'react-native-navigation'
22
import createLayout from './createLayout'
33

4-
interface SetRootCommand {
5-
(layoutRoot: LayoutRoot): Promise<any>
6-
(layout: Layout): Promise<any>
7-
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
8-
}
4+
import setRoot, { SetRootCommand } from './setRoot'
5+
import showModal, { ShowModalCommand } from './showModal'
6+
import showOverlay, { ShowOverlayCommand } from './showOverlay'
97

108
interface SetStackRootCommand {
119
<P = {}>(layout: Layout<P> | Layout<P>[]): Promise<any>
@@ -19,31 +17,45 @@ interface PushCommand {
1917
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
2018
}
2119

22-
interface ShowModalCommand {
23-
(layout: Layout): Promise<any>
24-
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
25-
}
26-
27-
interface ShowOverlayCommand {
28-
(layout: Layout): Promise<any>
29-
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
30-
}
31-
3220
export type NavigationCommands = {
33-
setRoot: SetRootCommand
3421
setStackRoot: SetStackRootCommand
3522
push: PushCommand
36-
showModal: ShowModalCommand
37-
showOverlay: ShowOverlayCommand
3823
mergeOptions: (options: Options) => void
3924
updateProps: (props: object) => void
4025
dismissModal: (mergeOptions?: Options) => Promise<any>
4126
pop: (mergeOptions?: Options) => Promise<any>
4227
popTo: (mergeOptions?: Options) => Promise<any>
4328
popToRoot: (mergeOptions?: Options) => Promise<any>
4429
dismissOverlay: () => Promise<any>
30+
31+
/**
32+
* @deprecated Use setRoot import from 'react-native-navigation-hooks'
33+
*/
34+
setRoot: SetRootCommand
35+
36+
/**
37+
* @deprecated Use setRoot import from 'react-native-navigation-hooks'
38+
*/
39+
showModal: ShowModalCommand
40+
41+
/**
42+
* @deprecated Use showOverlay import from 'react-native-navigation-hooks'
43+
*/
44+
showOverlay: ShowOverlayCommand
45+
46+
/**
47+
* @deprecated Use Navigation.setDefaultOptions instead
48+
*/
4549
setDefaultOptions: (options: Options) => void
50+
51+
/**
52+
* @deprecated Use Navigation.dismissAllModals instead
53+
*/
4654
dismissAllModals: (mergeOptions?: Options) => Promise<any>
55+
56+
/**
57+
* @deprecated Use Navigation.getLaunchArgs instead
58+
*/
4759
getLaunchArgs: () => Promise<any>
4860
}
4961

@@ -62,20 +74,6 @@ function createNavigationCommands(
6274
*/
6375
componentId: string
6476
): NavigationCommands {
65-
function setRoot<P = {}>(nameOrLayout: string | Layout | LayoutRoot, passProps?: P, options?: Options) {
66-
let layoutRoot
67-
68-
if (typeof nameOrLayout === 'string') {
69-
layoutRoot = { root: createLayout<P>(nameOrLayout, passProps, options) } as LayoutRoot
70-
} else if ((nameOrLayout as LayoutRoot).root) {
71-
layoutRoot = nameOrLayout as LayoutRoot
72-
} else {
73-
layoutRoot = { root: nameOrLayout } as LayoutRoot
74-
}
75-
76-
return Navigation.setRoot(layoutRoot)
77-
}
78-
7977
function setStackRoot<P = {}>(nameOrLayout: string | Layout<P> | Array<Layout<P>>, passProps?: P, options?: Options) {
8078
const layout = typeof nameOrLayout === 'string' ? createLayout<P>(nameOrLayout, passProps, options) : nameOrLayout
8179

@@ -88,18 +86,6 @@ function createNavigationCommands(
8886
return Navigation.push(componentId, layout)
8987
}
9088

91-
function showModal<P = {}>(nameOrLayout: string | Layout<P>, passProps?: P, options?: Options) {
92-
const layout = typeof nameOrLayout === 'string' ? createLayout<P>(nameOrLayout, passProps, options) : nameOrLayout
93-
94-
return Navigation.showModal(layout)
95-
}
96-
97-
function showOverlay<P = {}>(nameOrLayout: string | Layout<P>, passProps?: P, options?: Options) {
98-
const layout = typeof nameOrLayout === 'string' ? createLayout<P>(nameOrLayout, passProps, options) : nameOrLayout
99-
100-
return Navigation.showOverlay(layout)
101-
}
102-
10389
function mergeOptions(options: Options) {
10490
return Navigation.mergeOptions(componentId, options)
10591
}
@@ -135,18 +121,18 @@ function createNavigationCommands(
135121
const { setDefaultOptions, dismissAllModals, getLaunchArgs } = Navigation
136122

137123
return {
138-
setRoot,
139124
setStackRoot,
140125
push,
141-
showModal,
142-
showOverlay,
143126
mergeOptions,
144127
updateProps,
145128
dismissModal,
146129
pop,
147130
popTo,
148131
popToRoot,
149132
dismissOverlay,
133+
setRoot,
134+
showModal,
135+
showOverlay,
150136
setDefaultOptions,
151137
dismissAllModals,
152138
getLaunchArgs,

src/helpers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export { default as createLayout } from './createLayout'
22
export { default as createStack } from './createStack'
33
export { default as createNavigationCommands } from './createNavigationCommands'
4+
export { default as setRoot } from './setRoot'
5+
export { default as showModal } from './showModal'
6+
export { default as showOverlay } from './showOverlay'

src/helpers/setRoot.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Layout, LayoutRoot, Navigation, Options } from 'react-native-navigation'
2+
import createLayout from './createLayout'
3+
4+
export interface SetRootCommand {
5+
(layoutRoot: LayoutRoot): Promise<any>
6+
(layout: Layout): Promise<any>
7+
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
8+
}
9+
10+
function setRoot<P = {}>(nameOrLayout: string | Layout | LayoutRoot, passProps?: P, options?: Options) {
11+
let layoutRoot
12+
13+
if (typeof nameOrLayout === 'string') {
14+
layoutRoot = { root: createLayout<P>(nameOrLayout, passProps, options) } as LayoutRoot
15+
} else if ((nameOrLayout as LayoutRoot).root) {
16+
layoutRoot = nameOrLayout as LayoutRoot
17+
} else {
18+
layoutRoot = { root: nameOrLayout } as LayoutRoot
19+
}
20+
21+
return Navigation.setRoot(layoutRoot)
22+
}
23+
24+
export default setRoot

src/helpers/showModal.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Layout, Navigation, Options } from 'react-native-navigation'
2+
import createLayout from './createLayout'
3+
4+
export interface ShowModalCommand {
5+
(layout: Layout): Promise<any>
6+
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
7+
}
8+
9+
function showModal<P = {}>(nameOrLayout: string | Layout<P>, passProps?: P, options?: Options) {
10+
const layout = typeof nameOrLayout === 'string' ? createLayout<P>(nameOrLayout, passProps, options) : nameOrLayout
11+
12+
return Navigation.showModal(layout)
13+
}
14+
15+
export default showModal

src/helpers/showOverlay.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Layout, Navigation, Options } from 'react-native-navigation'
2+
import createLayout from './createLayout'
3+
4+
export interface ShowOverlayCommand {
5+
(layout: Layout): Promise<any>
6+
<P = {}>(name: string, passProps?: P, options?: Options): Promise<any>
7+
}
8+
9+
function showOverlay<P = {}>(nameOrLayout: string | Layout<P>, passProps?: P, options?: Options) {
10+
const layout = typeof nameOrLayout === 'string' ? createLayout<P>(nameOrLayout, passProps, options) : nameOrLayout
11+
12+
return Navigation.showOverlay(layout)
13+
}
14+
15+
export default showOverlay

0 commit comments

Comments
 (0)