@nativescript/core 8.8.0-next-07-01-2024-9747811047 → 8.8.0-pre-next-07-02-2024-9765997232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/application/application.android.d.ts +1 -1
  2. package/application/application.android.js +4 -0
  3. package/application/application.android.js.map +1 -1
  4. package/application/application.ios.d.ts +1 -1
  5. package/application/application.ios.js +2 -1
  6. package/application/application.ios.js.map +1 -1
  7. package/config/config.interface.d.ts +24 -0
  8. package/package.json +1 -1
  9. package/ui/embedding/index.android.d.ts +4 -0
  10. package/ui/embedding/index.android.js +14 -0
  11. package/ui/embedding/index.android.js.map +1 -0
  12. package/ui/embedding/index.d.ts +10 -0
  13. package/ui/embedding/index.ios.d.ts +1 -0
  14. package/ui/embedding/index.ios.js +4 -0
  15. package/ui/embedding/index.ios.js.map +1 -0
  16. package/ui/frame/activity.android.js +106 -47
  17. package/ui/frame/activity.android.js.map +1 -1
  18. package/ui/frame/callbacks/activity-callbacks.d.ts +19 -0
  19. package/ui/frame/callbacks/activity-callbacks.js +301 -0
  20. package/ui/frame/callbacks/activity-callbacks.js.map +1 -0
  21. package/ui/frame/callbacks/fragment-callbacks.d.ts +18 -0
  22. package/ui/frame/callbacks/fragment-callbacks.js +323 -0
  23. package/ui/frame/callbacks/fragment-callbacks.js.map +1 -0
  24. package/ui/frame/fragment.android.d.ts +3 -1
  25. package/ui/frame/fragment.android.js +40 -3
  26. package/ui/frame/fragment.android.js.map +1 -1
  27. package/ui/frame/fragment.d.ts +5 -0
  28. package/ui/frame/fragment.ios.d.ts +3 -0
  29. package/ui/frame/fragment.ios.js +4 -0
  30. package/ui/frame/fragment.ios.js.map +1 -0
  31. package/ui/frame/index.android.d.ts +3 -2
  32. package/ui/frame/index.android.js +6 -622
  33. package/ui/frame/index.android.js.map +1 -1
  34. package/ui/frame/index.d.ts +18 -0
  35. package/ui/index.d.ts +1 -0
  36. package/ui/index.js +1 -0
  37. package/ui/index.js.map +1 -1
@@ -1,22 +1,23 @@
1
1
  // Types.
2
2
  import { Application } from '../../application';
3
- import { Color } from '../../color';
4
3
  import { Observable } from '../../data/observable';
5
4
  import { Trace } from '../../trace';
6
5
  import { _stack, FrameBase, NavigationType } from './frame-common';
7
6
  import { _clearEntry, _clearFragment, _getAnimatedEntries, _reverseTransitions, _setAndroidFragmentTransitions, _updateTransitions, addNativeTransitionListener } from './fragment.transitions';
8
7
  import { profile } from '../../profiling';
9
8
  import { android as androidUtils } from '../../utils/native-helper';
9
+ import { ensureFragmentClass, fragmentClass } from './fragment';
10
+ import { FragmentCallbacksImplementation } from './callbacks/fragment-callbacks';
11
+ import { ActivityCallbacksImplementation } from './callbacks/activity-callbacks';
10
12
  export * from './frame-common';
13
+ export { setFragmentClass } from './fragment';
11
14
  const INTENT_EXTRA = 'com.tns.activity';
12
- const ROOT_VIEW_ID_EXTRA = 'com.tns.activity.rootViewId';
13
15
  const FRAMEID = '_frameId';
14
16
  const CALLBACKS = '_callbacks';
15
17
  const ownerSymbol = Symbol('_owner');
16
- const activityRootViewsMap = new Map();
17
18
  let navDepth = -1;
18
19
  let fragmentId = -1;
19
- export let moduleLoaded;
20
+ export { moduleLoaded } from './callbacks/activity-callbacks';
20
21
  export let attachStateChangeListener;
21
22
  function getAttachListener() {
22
23
  if (!attachStateChangeListener) {
@@ -616,36 +617,6 @@ class AndroidFrame extends Observable {
616
617
  return undefined;
617
618
  }
618
619
  }
619
- function findPageForFragment(fragment, frame) {
620
- const fragmentTag = fragment.getTag();
621
- if (Trace.isEnabled()) {
622
- Trace.write(`Finding page for ${fragmentTag}.`, Trace.categories.NativeLifecycle);
623
- }
624
- let entry;
625
- const current = frame._currentEntry;
626
- const executingContext = frame._executingContext;
627
- if (current && current.fragmentTag === fragmentTag) {
628
- entry = current;
629
- }
630
- else if (executingContext && executingContext.entry && executingContext.entry.fragmentTag === fragmentTag) {
631
- entry = executingContext.entry;
632
- }
633
- let page;
634
- if (entry) {
635
- entry.recreated = true;
636
- page = entry.resolvedPage;
637
- }
638
- if (page) {
639
- const callbacks = fragment[CALLBACKS];
640
- callbacks.frame = frame;
641
- callbacks.entry = entry;
642
- entry.fragment = fragment;
643
- _updateTransitions(entry);
644
- }
645
- else {
646
- throw new Error(`Could not find a page for ${fragmentTag}.`);
647
- }
648
- }
649
620
  function startActivity(activity, frameId) {
650
621
  // TODO: Implicitly, we will open the same activity type as the current one
651
622
  const intent = new android.content.Intent(activity, activity.getClass());
@@ -654,7 +625,7 @@ function startActivity(activity, frameId) {
654
625
  // TODO: Put the navigation context (if any) in the intent
655
626
  activity.startActivity(intent);
656
627
  }
657
- function getFrameByNumberId(frameId) {
628
+ export function getFrameByNumberId(frameId) {
658
629
  // Find the frame for this activity.
659
630
  for (let i = 0; i < framesCache.length; i++) {
660
631
  const aliveFrame = framesCache[i].get();
@@ -664,593 +635,6 @@ function getFrameByNumberId(frameId) {
664
635
  }
665
636
  return null;
666
637
  }
667
- function ensureFragmentClass() {
668
- if (fragmentClass) {
669
- return;
670
- }
671
- // this require will apply the FragmentClass implementation
672
- require('./fragment');
673
- if (!fragmentClass) {
674
- throw new Error('Failed to initialize the extended androidx.fragment.app.Fragment class');
675
- }
676
- }
677
- let fragmentClass;
678
- export function setFragmentClass(clazz) {
679
- if (fragmentClass) {
680
- throw new Error('Fragment class already initialized');
681
- }
682
- fragmentClass = clazz;
683
- }
684
- class FragmentCallbacksImplementation {
685
- constructor() {
686
- this.backgroundBitmap = null;
687
- }
688
- onHiddenChanged(fragment, hidden, superFunc) {
689
- if (Trace.isEnabled()) {
690
- Trace.write(`${fragment}.onHiddenChanged(${hidden})`, Trace.categories.NativeLifecycle);
691
- }
692
- superFunc.call(fragment, hidden);
693
- }
694
- onCreateAnimator(fragment, transit, enter, nextAnim, superFunc) {
695
- let animator = null;
696
- const entry = this.entry;
697
- // Return enterAnimator only when new (no current entry) nested transition.
698
- if (enter && entry.isNestedDefaultTransition) {
699
- animator = entry.enterAnimator;
700
- entry.isNestedDefaultTransition = false;
701
- }
702
- return animator || superFunc.call(fragment, transit, enter, nextAnim);
703
- }
704
- onCreate(fragment, savedInstanceState, superFunc) {
705
- if (Trace.isEnabled()) {
706
- Trace.write(`${fragment}.onCreate(${savedInstanceState})`, Trace.categories.NativeLifecycle);
707
- }
708
- superFunc.call(fragment, savedInstanceState);
709
- // There is no entry set to the fragment, so this must be destroyed fragment that was recreated by Android.
710
- // We should find its corresponding page in our backstack and set it manually.
711
- if (!this.entry) {
712
- const args = fragment.getArguments();
713
- const frameId = args.getInt(FRAMEID);
714
- const frame = getFrameByNumberId(frameId);
715
- if (!frame) {
716
- throw new Error(`Cannot find Frame for ${fragment}`);
717
- }
718
- findPageForFragment(fragment, frame);
719
- }
720
- }
721
- onCreateView(fragment, inflater, container, savedInstanceState, superFunc) {
722
- if (Trace.isEnabled()) {
723
- Trace.write(`${fragment}.onCreateView(inflater, container, ${savedInstanceState})`, Trace.categories.NativeLifecycle);
724
- }
725
- const entry = this.entry;
726
- if (!entry) {
727
- Trace.error(`${fragment}.onCreateView: entry is null or undefined`);
728
- return null;
729
- }
730
- const page = entry.resolvedPage;
731
- if (!page) {
732
- Trace.error(`${fragment}.onCreateView: entry has no resolvedPage`);
733
- return null;
734
- }
735
- const frame = this.frame;
736
- if (!frame) {
737
- Trace.error(`${fragment}.onCreateView: this.frame is null or undefined`);
738
- return null;
739
- }
740
- frame._resolvedPage = page;
741
- if (page.parent === frame) {
742
- frame._inheritStyles(page);
743
- // If we are navigating to a page that was destroyed
744
- // reinitialize its UI.
745
- if (!page._context) {
746
- const context = (container && container.getContext()) || (inflater && inflater.getContext());
747
- page._setupUI(context);
748
- }
749
- if (frame.isLoaded && !page.isLoaded) {
750
- page.callLoaded();
751
- }
752
- }
753
- else {
754
- if (!page.parent) {
755
- if (!frame._styleScope) {
756
- // Make sure page will have styleScope even if parents don't.
757
- page._updateStyleScope();
758
- }
759
- frame._addView(page);
760
- }
761
- else {
762
- throw new Error('Page is already shown on another frame.');
763
- }
764
- }
765
- const savedState = entry.viewSavedState;
766
- if (savedState) {
767
- page.nativeViewProtected.restoreHierarchyState(savedState);
768
- entry.viewSavedState = null;
769
- }
770
- // fixes 'java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first'.
771
- // on app resume in nested frame scenarios with support library version greater than 26.0.0
772
- // HACK: this whole code block shouldn't be necessary as the native view is supposedly removed from its parent
773
- // right after onDestroyView(...) is called but for some reason the fragment view (page) still thinks it has a
774
- // parent while its supposed parent believes it properly removed its children; in order to "force" the child to
775
- // lose its parent we temporarily add it to the parent, and then remove it (addViewInLayout doesn't trigger layout pass)
776
- const nativeView = page.nativeViewProtected;
777
- if (nativeView != null) {
778
- const parentView = nativeView.getParent();
779
- if (parentView instanceof android.view.ViewGroup) {
780
- if (parentView.getChildCount() === 0) {
781
- parentView.addViewInLayout(nativeView, -1, new org.nativescript.widgets.CommonLayoutParams());
782
- }
783
- parentView.removeAllViews();
784
- }
785
- }
786
- return page.nativeViewProtected;
787
- }
788
- onSaveInstanceState(fragment, outState, superFunc) {
789
- if (Trace.isEnabled()) {
790
- Trace.write(`${fragment}.onSaveInstanceState(${outState})`, Trace.categories.NativeLifecycle);
791
- }
792
- superFunc.call(fragment, outState);
793
- }
794
- onDestroyView(fragment, superFunc) {
795
- try {
796
- if (Trace.isEnabled()) {
797
- Trace.write(`${fragment}.onDestroyView()`, Trace.categories.NativeLifecycle);
798
- }
799
- const hasRemovingParent = fragment.getRemovingParentFragment();
800
- if (hasRemovingParent) {
801
- const nativeFrameView = this.frame.nativeViewProtected;
802
- if (nativeFrameView) {
803
- const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(Application.android.context.getResources(), this.backgroundBitmap);
804
- this.frame._originalBackground = this.frame.backgroundColor || new Color('White');
805
- nativeFrameView.setBackgroundDrawable(bitmapDrawable);
806
- this.backgroundBitmap = null;
807
- }
808
- }
809
- }
810
- finally {
811
- superFunc.call(fragment);
812
- }
813
- }
814
- onDestroy(fragment, superFunc) {
815
- if (Trace.isEnabled()) {
816
- Trace.write(`${fragment}.onDestroy()`, Trace.categories.NativeLifecycle);
817
- }
818
- superFunc.call(fragment);
819
- const entry = this.entry;
820
- if (!entry) {
821
- Trace.error(`${fragment}.onDestroy: entry is null or undefined`);
822
- return null;
823
- }
824
- // [nested frames / fragments] see https://github.com/NativeScript/NativeScript/issues/6629
825
- // retaining reference to a destroyed fragment here somehow causes a cryptic
826
- // "IllegalStateException: Failure saving state: active fragment has cleared index: -1"
827
- // in a specific mixed parent / nested frame navigation scenario
828
- entry.fragment = null;
829
- const page = entry.resolvedPage;
830
- if (!page) {
831
- // todo: check why this happens when using shared element transition!!!
832
- // commented out the Trace.error to prevent a crash (the app will still work interestingly)
833
- console.log(`${fragment}.onDestroy: entry has no resolvedPage`);
834
- // Trace.error(`${fragment}.onDestroy: entry has no resolvedPage`);
835
- return null;
836
- }
837
- }
838
- onPause(fragment, superFunc) {
839
- try {
840
- // Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
841
- // TODO: Consider removing it when update to androidx.fragment:1.2.0
842
- const hasRemovingParent = fragment.getRemovingParentFragment();
843
- if (hasRemovingParent) {
844
- this.backgroundBitmap = this.loadBitmapFromView(this.frame.nativeViewProtected);
845
- }
846
- }
847
- finally {
848
- superFunc.call(fragment);
849
- }
850
- }
851
- onResume(fragment, superFunc) {
852
- const frame = this.entry.resolvedPage.frame;
853
- // on some cases during the first navigation on nested frames the animation doesn't trigger
854
- // we depend on the animation (even None animation) to set the entry as the current entry
855
- // animation should start between start and resume, so if we have an executing navigation here it probably means the animation was skipped
856
- // so we manually set the entry
857
- // also, to be compatible with fragments 1.2.x we need this setTimeout as animations haven't run on onResume yet
858
- const weakRef = new WeakRef(this);
859
- setTimeout(() => {
860
- const owner = weakRef.get();
861
- if (!owner) {
862
- return;
863
- }
864
- if (frame._executingContext && !owner.entry.isAnimationRunning) {
865
- frame.setCurrent(owner.entry, frame._executingContext.navigationType);
866
- }
867
- }, 0);
868
- superFunc.call(fragment);
869
- }
870
- onStop(fragment, superFunc) {
871
- superFunc.call(fragment);
872
- }
873
- toStringOverride(fragment, superFunc) {
874
- const entry = this.entry;
875
- if (entry) {
876
- return `${entry.fragmentTag}<${entry.resolvedPage}>`;
877
- }
878
- else {
879
- return 'NO ENTRY, ' + superFunc.call(fragment);
880
- }
881
- }
882
- loadBitmapFromView(view) {
883
- // Don't try to create bitmaps with no dimensions as this causes a crash
884
- // This might happen when showing and closing dialogs fast.
885
- if (!(view && view.getWidth() > 0 && view.getHeight() > 0)) {
886
- return undefined;
887
- }
888
- // Another way to get view bitmap. Test performance vs setDrawingCacheEnabled
889
- // const width = view.getWidth();
890
- // const height = view.getHeight();
891
- // const bitmap = android.graphics.Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
892
- // const canvas = new android.graphics.Canvas(bitmap);
893
- // view.layout(0, 0, width, height);
894
- // view.draw(canvas);
895
- // view.setDrawingCacheEnabled(true);
896
- // const drawCache = view.getDrawingCache();
897
- // const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
898
- // view.setDrawingCacheEnabled(false);
899
- return org.nativescript.widgets.Utils.getBitmapFromView(view);
900
- }
901
- }
902
- __decorate([
903
- profile,
904
- __metadata("design:type", Function),
905
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, Boolean, Function]),
906
- __metadata("design:returntype", void 0)
907
- ], FragmentCallbacksImplementation.prototype, "onHiddenChanged", null);
908
- __decorate([
909
- profile,
910
- __metadata("design:type", Function),
911
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, Number, Boolean, Number, Function]),
912
- __metadata("design:returntype", android.animation.Animator)
913
- ], FragmentCallbacksImplementation.prototype, "onCreateAnimator", null);
914
- __decorate([
915
- profile,
916
- __metadata("design:type", Function),
917
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, android.os.Bundle, Function]),
918
- __metadata("design:returntype", void 0)
919
- ], FragmentCallbacksImplementation.prototype, "onCreate", null);
920
- __decorate([
921
- profile,
922
- __metadata("design:type", Function),
923
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle, Function]),
924
- __metadata("design:returntype", android.view.View)
925
- ], FragmentCallbacksImplementation.prototype, "onCreateView", null);
926
- __decorate([
927
- profile,
928
- __metadata("design:type", Function),
929
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, android.os.Bundle, Function]),
930
- __metadata("design:returntype", void 0)
931
- ], FragmentCallbacksImplementation.prototype, "onSaveInstanceState", null);
932
- __decorate([
933
- profile,
934
- __metadata("design:type", Function),
935
- __metadata("design:paramtypes", [org.nativescript.widgets.FragmentBase, Function]),
936
- __metadata("design:returntype", void 0)
937
- ], FragmentCallbacksImplementation.prototype, "onDestroyView", null);
938
- __decorate([
939
- profile,
940
- __metadata("design:type", Function),
941
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, Function]),
942
- __metadata("design:returntype", void 0)
943
- ], FragmentCallbacksImplementation.prototype, "onDestroy", null);
944
- __decorate([
945
- profile,
946
- __metadata("design:type", Function),
947
- __metadata("design:paramtypes", [org.nativescript.widgets.FragmentBase, Function]),
948
- __metadata("design:returntype", void 0)
949
- ], FragmentCallbacksImplementation.prototype, "onPause", null);
950
- __decorate([
951
- profile,
952
- __metadata("design:type", Function),
953
- __metadata("design:paramtypes", [org.nativescript.widgets.FragmentBase, Function]),
954
- __metadata("design:returntype", void 0)
955
- ], FragmentCallbacksImplementation.prototype, "onResume", null);
956
- __decorate([
957
- profile,
958
- __metadata("design:type", Function),
959
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, Function]),
960
- __metadata("design:returntype", void 0)
961
- ], FragmentCallbacksImplementation.prototype, "onStop", null);
962
- __decorate([
963
- profile,
964
- __metadata("design:type", Function),
965
- __metadata("design:paramtypes", [androidx.fragment.app.Fragment, Function]),
966
- __metadata("design:returntype", String)
967
- ], FragmentCallbacksImplementation.prototype, "toStringOverride", null);
968
- class ActivityCallbacksImplementation {
969
- getRootView() {
970
- return this._rootView;
971
- }
972
- onCreate(activity, savedInstanceState, intentOrSuperFunc, superFunc) {
973
- if (Trace.isEnabled()) {
974
- Trace.write(`Activity.onCreate(${savedInstanceState})`, Trace.categories.NativeLifecycle);
975
- }
976
- const intent = superFunc ? intentOrSuperFunc : undefined;
977
- if (!superFunc) {
978
- console.log('AndroidActivityCallbacks.onCreate(activity: any, savedInstanceState: any, superFunc: Function) ' + 'is deprecated. Use AndroidActivityCallbacks.onCreate(activity: any, savedInstanceState: any, intent: any, superFunc: Function) instead.');
979
- superFunc = intentOrSuperFunc;
980
- }
981
- // If there is savedInstanceState this call will recreate all fragments that were previously in the navigation.
982
- // We take care of associating them with a Page from our backstack in the onAttachFragment callback.
983
- // If there is savedInstanceState and moduleLoaded is false we are restarted but process was killed.
984
- // For now we treat it like first run (e.g. we are not passing savedInstanceState so no fragments are being restored).
985
- // When we add support for application save/load state - revise this logic.
986
- const isRestart = !!savedInstanceState && moduleLoaded;
987
- superFunc.call(activity, isRestart ? savedInstanceState : null);
988
- // Try to get the rootViewId form the saved state in case the activity
989
- // was destroyed and we are now recreating it.
990
- if (savedInstanceState) {
991
- const rootViewId = savedInstanceState.getInt(ROOT_VIEW_ID_EXTRA, -1);
992
- if (rootViewId !== -1 && activityRootViewsMap.has(rootViewId)) {
993
- this._rootView = activityRootViewsMap.get(rootViewId)?.get();
994
- }
995
- }
996
- if (intent && intent.getAction()) {
997
- Application.android.notify({
998
- eventName: Application.AndroidApplication.activityNewIntentEvent,
999
- object: Application.android,
1000
- activity,
1001
- intent,
1002
- });
1003
- }
1004
- this.setActivityContent(activity, savedInstanceState, true);
1005
- moduleLoaded = true;
1006
- }
1007
- onSaveInstanceState(activity, outState, superFunc) {
1008
- superFunc.call(activity, outState);
1009
- const rootView = this._rootView;
1010
- if (rootView instanceof Frame) {
1011
- outState.putInt(INTENT_EXTRA, rootView.android.frameId);
1012
- rootView._saveFragmentsState();
1013
- }
1014
- if (rootView) {
1015
- outState.putInt(ROOT_VIEW_ID_EXTRA, rootView._domId);
1016
- }
1017
- }
1018
- onNewIntent(activity, intent, superSetIntentFunc, superFunc) {
1019
- superFunc.call(activity, intent);
1020
- superSetIntentFunc.call(activity, intent);
1021
- Application.android.notify({
1022
- eventName: Application.AndroidApplication.activityNewIntentEvent,
1023
- object: Application.android,
1024
- activity,
1025
- intent,
1026
- });
1027
- }
1028
- onStart(activity, superFunc) {
1029
- superFunc.call(activity);
1030
- if (Trace.isEnabled()) {
1031
- Trace.write('NativeScriptActivity.onStart();', Trace.categories.NativeLifecycle);
1032
- }
1033
- const rootView = this._rootView;
1034
- if (rootView && !rootView.isLoaded) {
1035
- rootView.callLoaded();
1036
- }
1037
- }
1038
- onStop(activity, superFunc) {
1039
- superFunc.call(activity);
1040
- if (Trace.isEnabled()) {
1041
- Trace.write('NativeScriptActivity.onStop();', Trace.categories.NativeLifecycle);
1042
- }
1043
- const rootView = this._rootView;
1044
- if (rootView && rootView.isLoaded) {
1045
- rootView.callUnloaded();
1046
- }
1047
- }
1048
- onPostResume(activity, superFunc) {
1049
- superFunc.call(activity);
1050
- if (Trace.isEnabled()) {
1051
- Trace.write('NativeScriptActivity.onPostResume();', Trace.categories.NativeLifecycle);
1052
- }
1053
- // NOTE: activity.onPostResume() is called when activity resume is complete and we can
1054
- // safely raise the application resume event;
1055
- // onActivityResumed(...) lifecycle callback registered in application is called too early
1056
- // and raising the application resume event there causes issues like
1057
- // https://github.com/NativeScript/NativeScript/issues/6708
1058
- if (activity.isNativeScriptActivity) {
1059
- Application.setSuspended(false, {
1060
- // todo: deprecate in favor of using event.activity instead.
1061
- android: activity,
1062
- activity,
1063
- });
1064
- }
1065
- }
1066
- onDestroy(activity, superFunc) {
1067
- try {
1068
- if (Trace.isEnabled()) {
1069
- Trace.write('NativeScriptActivity.onDestroy();', Trace.categories.NativeLifecycle);
1070
- }
1071
- const rootView = this._rootView;
1072
- if (rootView) {
1073
- rootView._tearDownUI(true);
1074
- }
1075
- // this may happen when the user changes the system theme
1076
- // In such case, isFinishing() is false (and isChangingConfigurations is true), and the app will start again (onCreate) with a savedInstanceState
1077
- // as a result, launchEvent will never be called
1078
- // possible alternative: always fire launchEvent and exitEvent, but pass extra flags to make it clear what kind of launch/destroy is happening
1079
- if (activity.isFinishing()) {
1080
- const exitArgs = {
1081
- eventName: Application.exitEvent,
1082
- object: Application.android,
1083
- android: activity,
1084
- };
1085
- Application.notify(exitArgs);
1086
- }
1087
- }
1088
- finally {
1089
- superFunc.call(activity);
1090
- }
1091
- }
1092
- onBackPressed(activity, superFunc) {
1093
- if (Trace.isEnabled()) {
1094
- Trace.write('NativeScriptActivity.onBackPressed;', Trace.categories.NativeLifecycle);
1095
- }
1096
- const args = {
1097
- eventName: 'activityBackPressed',
1098
- object: Application,
1099
- android: Application.android,
1100
- activity: activity,
1101
- cancel: false,
1102
- };
1103
- Application.android.notify(args);
1104
- if (args.cancel) {
1105
- return;
1106
- }
1107
- const view = this._rootView;
1108
- let callSuper = false;
1109
- const viewArgs = {
1110
- eventName: 'activityBackPressed',
1111
- object: view,
1112
- activity: activity,
1113
- cancel: false,
1114
- };
1115
- view.notify(viewArgs);
1116
- // In the case of Frame, use this callback only if it was overridden, since the original will cause navigation issues
1117
- if (!viewArgs.cancel && (view.onBackPressed === Frame.prototype.onBackPressed || !view.onBackPressed())) {
1118
- callSuper = view instanceof Frame ? !FrameBase.goBack() : true;
1119
- }
1120
- if (callSuper) {
1121
- superFunc.call(activity);
1122
- }
1123
- }
1124
- onRequestPermissionsResult(activity, requestCode, permissions, grantResults, superFunc) {
1125
- if (Trace.isEnabled()) {
1126
- Trace.write('NativeScriptActivity.onRequestPermissionsResult;', Trace.categories.NativeLifecycle);
1127
- }
1128
- Application.android.notify({
1129
- eventName: 'activityRequestPermissions',
1130
- object: Application,
1131
- android: Application.android,
1132
- activity: activity,
1133
- requestCode: requestCode,
1134
- permissions: permissions,
1135
- grantResults: grantResults,
1136
- });
1137
- }
1138
- onActivityResult(activity, requestCode, resultCode, data, superFunc) {
1139
- superFunc.call(activity, requestCode, resultCode, data);
1140
- if (Trace.isEnabled()) {
1141
- Trace.write(`NativeScriptActivity.onActivityResult(${requestCode}, ${resultCode}, ${data})`, Trace.categories.NativeLifecycle);
1142
- }
1143
- Application.android.notify({
1144
- eventName: 'activityResult',
1145
- object: Application,
1146
- android: Application.android,
1147
- activity: activity,
1148
- requestCode: requestCode,
1149
- resultCode: resultCode,
1150
- intent: data,
1151
- });
1152
- }
1153
- resetActivityContent(activity) {
1154
- if (this._rootView) {
1155
- const manager = this._rootView._getFragmentManager();
1156
- manager.executePendingTransactions();
1157
- this._rootView._onRootViewReset();
1158
- }
1159
- // Delete previously cached root view in order to recreate it.
1160
- this._rootView = null;
1161
- this.setActivityContent(activity, null, false);
1162
- this._rootView.callLoaded();
1163
- }
1164
- // Paths that go trough this method:
1165
- // 1. Application initial start - there is no rootView in callbacks.
1166
- // 2. Application revived after Activity is destroyed. this._rootView should have been restored by id in onCreate.
1167
- // 3. Livesync if rootView has no custom _onLivesync. this._rootView should have been cleared upfront. Launch event should not fired
1168
- // 4. resetRootView method. this._rootView should have been cleared upfront. Launch event should not fired
1169
- setActivityContent(activity, savedInstanceState, fireLaunchEvent) {
1170
- let rootView = this._rootView;
1171
- if (Trace.isEnabled()) {
1172
- Trace.write(`Frame.setActivityContent rootView: ${rootView} shouldCreateRootFrame: false fireLaunchEvent: ${fireLaunchEvent}`, Trace.categories.NativeLifecycle);
1173
- }
1174
- const intent = activity.getIntent();
1175
- rootView = Application.createRootView(rootView, fireLaunchEvent, {
1176
- // todo: deprecate in favor of args.intent?
1177
- android: intent,
1178
- intent,
1179
- savedInstanceState,
1180
- });
1181
- if (!rootView) {
1182
- // no root view created
1183
- return;
1184
- }
1185
- activityRootViewsMap.set(rootView._domId, new WeakRef(rootView));
1186
- // setup view as styleScopeHost
1187
- rootView._setupAsRootView(activity);
1188
- activity.setContentView(rootView.nativeViewProtected, new org.nativescript.widgets.CommonLayoutParams());
1189
- this._rootView = rootView;
1190
- // sets root classes once rootView is ready...
1191
- Application.initRootView(rootView);
1192
- }
1193
- }
1194
- __decorate([
1195
- profile,
1196
- __metadata("design:type", Function),
1197
- __metadata("design:paramtypes", [androidx.appcompat.app.AppCompatActivity, android.os.Bundle, Object, Function]),
1198
- __metadata("design:returntype", void 0)
1199
- ], ActivityCallbacksImplementation.prototype, "onCreate", null);
1200
- __decorate([
1201
- profile,
1202
- __metadata("design:type", Function),
1203
- __metadata("design:paramtypes", [androidx.appcompat.app.AppCompatActivity, android.os.Bundle, Function]),
1204
- __metadata("design:returntype", void 0)
1205
- ], ActivityCallbacksImplementation.prototype, "onSaveInstanceState", null);
1206
- __decorate([
1207
- profile,
1208
- __metadata("design:type", Function),
1209
- __metadata("design:paramtypes", [androidx.appcompat.app.AppCompatActivity, android.content.Intent, Function, Function]),
1210
- __metadata("design:returntype", void 0)
1211
- ], ActivityCallbacksImplementation.prototype, "onNewIntent", null);
1212
- __decorate([
1213
- profile,
1214
- __metadata("design:type", Function),
1215
- __metadata("design:paramtypes", [Object, Function]),
1216
- __metadata("design:returntype", void 0)
1217
- ], ActivityCallbacksImplementation.prototype, "onStart", null);
1218
- __decorate([
1219
- profile,
1220
- __metadata("design:type", Function),
1221
- __metadata("design:paramtypes", [Object, Function]),
1222
- __metadata("design:returntype", void 0)
1223
- ], ActivityCallbacksImplementation.prototype, "onStop", null);
1224
- __decorate([
1225
- profile,
1226
- __metadata("design:type", Function),
1227
- __metadata("design:paramtypes", [Object, Function]),
1228
- __metadata("design:returntype", void 0)
1229
- ], ActivityCallbacksImplementation.prototype, "onPostResume", null);
1230
- __decorate([
1231
- profile,
1232
- __metadata("design:type", Function),
1233
- __metadata("design:paramtypes", [Object, Function]),
1234
- __metadata("design:returntype", void 0)
1235
- ], ActivityCallbacksImplementation.prototype, "onDestroy", null);
1236
- __decorate([
1237
- profile,
1238
- __metadata("design:type", Function),
1239
- __metadata("design:paramtypes", [Object, Function]),
1240
- __metadata("design:returntype", void 0)
1241
- ], ActivityCallbacksImplementation.prototype, "onBackPressed", null);
1242
- __decorate([
1243
- profile,
1244
- __metadata("design:type", Function),
1245
- __metadata("design:paramtypes", [Object, Number, Array, Array, Function]),
1246
- __metadata("design:returntype", void 0)
1247
- ], ActivityCallbacksImplementation.prototype, "onRequestPermissionsResult", null);
1248
- __decorate([
1249
- profile,
1250
- __metadata("design:type", Function),
1251
- __metadata("design:paramtypes", [Object, Number, Number, android.content.Intent, Function]),
1252
- __metadata("design:returntype", void 0)
1253
- ], ActivityCallbacksImplementation.prototype, "onActivityResult", null);
1254
638
  export function setActivityCallbacks(activity) {
1255
639
  activity[CALLBACKS] = new ActivityCallbacksImplementation();
1256
640
  }