-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
SharedElementCompatRouteProxy.ts
54 lines (45 loc) · 1.63 KB
/
SharedElementCompatRouteProxy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { SharedElementRoute, SharedElementCompatRoute } from "./types";
export class SharedElementCompatRouteProxy implements SharedElementCompatRoute {
static isParamWarningSilenced = false;
static isStateWarningSilenced = false;
private route: SharedElementRoute;
private deprecatedStateCache: any;
constructor(route: SharedElementRoute) {
this.route = route;
}
get key(): string {
return this.route.key;
}
get name(): string {
return this.route.name;
}
get params(): { [key: string]: any } {
return this.route.params || {};
}
// As of react-navigation-shared-element@3, the `sharedElements` function
// receives a route rather than a navigator. In order to easy the code transition
// both the `navigation` and `route` forms are supported. When using `navigation`.
getParam(name: string): any {
if (!SharedElementCompatRouteProxy.isParamWarningSilenced) {
SharedElementCompatRouteProxy.isParamWarningSilenced = true;
console.warn(
'SharedElementNavigation: `navigation.getParam() is deprecated, use `route.params` instead. See TODO"'
);
}
return this.params[name];
}
get state(): any {
if (!SharedElementCompatRouteProxy.isStateWarningSilenced) {
SharedElementCompatRouteProxy.isStateWarningSilenced = true;
console.warn(
'SharedElementNavigation: `navigation.state[key/routeName] is deprecated, use `route[key/name]` instead. See TODO"'
);
}
this.deprecatedStateCache = this.deprecatedStateCache || {
key: this.key,
routeName: this.name,
params: this.params,
};
return this.deprecatedStateCache;
}
}