UNPKG

3.02 kBJavaScriptView Raw
1import { isEmbedded, getEmbeddedView } from '../embedding';
2import { setFragmentCallbacks } from '.';
3const superProto = org.nativescript.widgets.FragmentBase.prototype;
4const FragmentClass = org.nativescript.widgets.FragmentBase.extend('com.tns.FragmentClass', {
5 init() { },
6 onHiddenChanged(hidden) {
7 this._callbacks.onHiddenChanged(this, hidden, superProto.onHiddenChanged);
8 },
9 onCreateAnimator(transit, enter, nextAnim) {
10 return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, superProto.onCreateAnimator);
11 },
12 onStop() {
13 this._callbacks.onStop(this, superProto.onStop);
14 },
15 onPause() {
16 this._callbacks.onPause(this, superProto.onPause);
17 },
18 onResume() {
19 this._callbacks.onResume(this, superProto.onResume);
20 },
21 onCreate(savedInstanceState) {
22 if (!this._callbacks) {
23 setFragmentCallbacks(this);
24 }
25 this.setHasOptionsMenu(true);
26 this._callbacks.onCreate(this, savedInstanceState, superProto.onCreate);
27 },
28 onCreateView(inflater, container, savedInstanceState) {
29 return this._callbacks.onCreateView(this, inflater, container, savedInstanceState, superProto.onCreateView);
30 },
31 onSaveInstanceState(outState) {
32 this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
33 },
34 onDestroyView() {
35 this._callbacks.onDestroyView(this, superProto.onDestroyView);
36 },
37 onDestroy() {
38 this._callbacks.onDestroy(this, superProto.onDestroy);
39 this._callbacks = null;
40 },
41 toString() {
42 const callbacks = this._callbacks;
43 if (callbacks) {
44 return callbacks.toStringOverride(this, superProto.toString);
45 }
46 else {
47 superProto.toString();
48 }
49 },
50});
51export let fragmentClass;
52export function ensureFragmentClass() {
53 if (fragmentClass) {
54 return;
55 }
56 // this require will apply the FragmentClass implementation
57 require('./fragment');
58 if (!fragmentClass) {
59 throw new Error('Failed to initialize the extended androidx.fragment.app.Fragment class');
60 }
61}
62export function setFragmentClass(clazz) {
63 if (fragmentClass) {
64 throw new Error('Fragment class already initialized');
65 }
66 if (isEmbedded()) {
67 attachEmbeddableFragmentCallbacks();
68 }
69 fragmentClass = clazz;
70}
71function attachEmbeddableFragmentCallbacks() {
72 const Callbacks = com.tns.embedding.EmbeddableFragmentCallbacks.extend({
73 init() {
74 // init must at least be defined
75 },
76 onCreateView() {
77 return getEmbeddedView().nativeViewProtected;
78 },
79 onResume() {
80 getEmbeddedView().callLoaded();
81 },
82 onPause() {
83 getEmbeddedView().callUnloaded();
84 },
85 });
86 com.tns.embedding.CallbacksStore.setFragmentCallbacks(new Callbacks());
87}
88setFragmentClass(FragmentClass);
89//# sourceMappingURL=fragment.android.js.map
\No newline at end of file