Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js": true,
"**/*.js.map": true
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
Expand Down
24 changes: 12 additions & 12 deletions tns-core-modules/application/application.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class AndroidApplication extends Observable implements AndroidApplication
public paused: boolean;
public nativeApp: android.app.Application;
public context: android.content.Context;
public foregroundActivity: android.app.Activity;
public startActivity: android.app.Activity;
public foregroundActivity: android.support.v7.app.AppCompatActivity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate a bit why is the change to android.support.v7.app.AppCompat* APIs necessary for supporting shared element transitions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i made a all replace. I think you ate right in this case it should still be an activity as you can start another activity which would not be an AppCompatActivity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still trying to get my head around why we need the AppCompat* API switch at all. Can you elaborate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manoldonev You need to compat switch to get access to many methods, like startPostponedEnterTransition on fragments and activities.
You also need supportFinishAfterTransition to make sure transitions are applied when closing an activity.
Also i really want to point out that in P, they deprecate the default FragmentManager so you need to start using the support library anyway.
On a side note it wont make apps bigger as your already include it.

public startActivity: android.support.v7.app.AppCompatActivity;
public packageName: string;

public get currentContext(): android.content.Context {
Expand Down Expand Up @@ -218,7 +218,7 @@ global.__onLiveSync = function () {
};

function initLifecycleCallbacks() {
const setThemeOnLaunch = profile("setThemeOnLaunch", (activity: android.app.Activity) => {
const setThemeOnLaunch = profile("setThemeOnLaunch", (activity: android.support.v7.app.AppCompatActivity) => {
// Set app theme after launch screen was used during startup
const activityInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), android.content.pm.PackageManager.GET_META_DATA);
if (activityInfo.metaData) {
Expand All @@ -229,11 +229,11 @@ function initLifecycleCallbacks() {
}
});

const notifyActivityCreated = profile("notifyActivityCreated", function (activity: android.app.Activity, savedInstanceState: android.os.Bundle) {
const notifyActivityCreated = profile("notifyActivityCreated", function (activity: android.support.v7.app.AppCompatActivity, savedInstanceState: android.os.Bundle) {
androidApp.notify(<AndroidActivityBundleEventData>{ eventName: ActivityCreated, object: androidApp, activity, bundle: savedInstanceState });
});

const subscribeForGlobalLayout = profile("subscribeForGlobalLayout", function (activity: android.app.Activity) {
const subscribeForGlobalLayout = profile("subscribeForGlobalLayout", function (activity: android.support.v7.app.AppCompatActivity) {
const rootView = activity.getWindow().getDecorView().getRootView();
let onGlobalLayoutListener = new android.view.ViewTreeObserver.OnGlobalLayoutListener({
onGlobalLayout() {
Expand All @@ -246,7 +246,7 @@ function initLifecycleCallbacks() {
});

const lifecycleCallbacks = new android.app.Application.ActivityLifecycleCallbacks({
onActivityCreated: profile("onActivityCreated", function (activity: android.app.Activity, savedInstanceState: android.os.Bundle) {
onActivityCreated: profile("onActivityCreated", function (activity: android.support.v7.app.AppCompatActivity, savedInstanceState: android.os.Bundle) {
setThemeOnLaunch(activity);

if (!androidApp.startActivity) {
Expand All @@ -260,7 +260,7 @@ function initLifecycleCallbacks() {
}
}),

onActivityDestroyed: profile("onActivityDestroyed", function (activity: android.app.Activity) {
onActivityDestroyed: profile("onActivityDestroyed", function (activity: android.support.v7.app.AppCompatActivity) {
if (activity === androidApp.foregroundActivity) {
androidApp.foregroundActivity = undefined;
}
Expand All @@ -274,7 +274,7 @@ function initLifecycleCallbacks() {
gc();
}),

onActivityPaused: profile("onActivityPaused", function (activity: android.app.Activity) {
onActivityPaused: profile("onActivityPaused", function (activity: android.support.v7.app.AppCompatActivity) {
if ((<any>activity).isNativeScriptActivity) {
androidApp.paused = true;
notify(<ApplicationEventData>{ eventName: suspendEvent, object: androidApp, android: activity });
Expand All @@ -283,7 +283,7 @@ function initLifecycleCallbacks() {
androidApp.notify(<AndroidActivityEventData>{ eventName: ActivityPaused, object: androidApp, activity: activity });
}),

onActivityResumed: profile("onActivityResumed", function (activity: android.app.Activity) {
onActivityResumed: profile("onActivityResumed", function (activity: android.support.v7.app.AppCompatActivity) {
androidApp.foregroundActivity = activity;

if ((<any>activity).isNativeScriptActivity) {
Expand All @@ -294,15 +294,15 @@ function initLifecycleCallbacks() {
androidApp.notify(<AndroidActivityEventData>{ eventName: ActivityResumed, object: androidApp, activity: activity });
}),

onActivitySaveInstanceState: profile("onActivityResumed", function (activity: android.app.Activity, outState: android.os.Bundle) {
onActivitySaveInstanceState: profile("onActivityResumed", function (activity: android.support.v7.app.AppCompatActivity, outState: android.os.Bundle) {
androidApp.notify(<AndroidActivityBundleEventData>{ eventName: SaveActivityState, object: androidApp, activity: activity, bundle: outState });
}),

onActivityStarted: profile("onActivityStarted", function (activity: android.app.Activity) {
onActivityStarted: profile("onActivityStarted", function (activity: android.support.v7.app.AppCompatActivity) {
androidApp.notify(<AndroidActivityEventData>{ eventName: ActivityStarted, object: androidApp, activity: activity });
}),

onActivityStopped: profile("onActivityStopped", function (activity: android.app.Activity) {
onActivityStopped: profile("onActivityStopped", function (activity: android.support.v7.app.AppCompatActivity) {
androidApp.notify(<AndroidActivityEventData>{ eventName: ActivityStopped, object: androidApp, activity: activity });
})
});
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/application/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export interface AndroidActivityEventData {
/**
* The activity.
*/
activity: any /* android.app.Activity */;
activity: any /* android.support.v7.app.AppCompatActivity */;

/**
* The name of the event.
Expand Down
6 changes: 5 additions & 1 deletion tns-core-modules/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
//END Style property shortcuts

public automationText: string;
public transitionName: string;
public originX: number;
public originY: number;
public isEnabled: boolean;
Expand Down Expand Up @@ -1010,4 +1011,7 @@ export const isEnabledProperty = new Property<ViewCommon, boolean>({
isEnabledProperty.register(ViewCommon);

export const isUserInteractionEnabledProperty = new Property<ViewCommon, boolean>({ name: "isUserInteractionEnabled", defaultValue: true, valueConverter: booleanConverter });
isUserInteractionEnabledProperty.register(ViewCommon);
isUserInteractionEnabledProperty.register(ViewCommon);

export const transitionNameProperty = new Property<ViewCommon, string>({ name: "transitionNameProperty" });
transitionNameProperty.register(ViewCommon);
20 changes: 12 additions & 8 deletions tns-core-modules/ui/core/view/view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AndroidActivityBackPressedEventData } from "../../../application";
import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
traceEnabled, traceWrite, traceCategories, traceNotifyEvent,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, transitionNameProperty,
Color
} from "./view-common";

Expand Down Expand Up @@ -49,7 +49,7 @@ interface TouchListener {
}

interface DialogFragment {
new(): android.app.DialogFragment;
new(): android.support.v4.app.DialogFragment;
}

function initializeDisabledListener(): void {
Expand Down Expand Up @@ -122,7 +122,7 @@ function initializeDialogFragment() {
}
}

class DialogFragmentImpl extends android.app.DialogFragment {
class DialogFragmentImpl extends android.support.v4.app.DialogFragment {
public owner: View;
private _fullscreen: boolean;
private _stretched: boolean;
Expand All @@ -143,7 +143,7 @@ function initializeDialogFragment() {
this._dismissCallback = options.dismissCallback;
this._shownCallback = options.shownCallback;
this.owner._dialogFragment = this;
this.setStyle(android.app.DialogFragment.STYLE_NO_TITLE, 0);
this.setStyle(android.support.v4.app.DialogFragment.STYLE_NO_TITLE, 0);

const dialog = new DialogImpl(this, this.getActivity(), this.getTheme());

Expand Down Expand Up @@ -227,11 +227,11 @@ function getModalOptions(domId: number): DialogOptions {
export class View extends ViewCommon {
public static androidBackPressedEvent = androidBackPressedEvent;

public _dialogFragment: android.app.DialogFragment;
public _dialogFragment: android.support.v4.app.DialogFragment;
private _isClickable: boolean;
private touchListenerIsSet: boolean;
private touchListener: android.view.View.OnTouchListener;
private _manager: android.app.FragmentManager;
private _manager: android.support.v4.app.FragmentManager;

nativeViewProtected: android.view.View;

Expand All @@ -243,7 +243,7 @@ export class View extends ViewCommon {
}
}

public _getFragmentManager(): android.app.FragmentManager {
public _getFragmentManager(): android.support.v4.app.FragmentManager {
let manager = this._manager;
if (!manager) {
let view: View = this;
Expand All @@ -260,7 +260,7 @@ export class View extends ViewCommon {
}

if (!manager && this._context) {
manager = (<android.app.Activity>this._context).getFragmentManager();
manager = (<android.support.v7.app.AppCompatActivity>this._context).getSupportFragmentManager();
}

this._manager = manager;
Expand Down Expand Up @@ -334,6 +334,7 @@ export class View extends ViewCommon {
return false;
}


public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
if (this.nativeViewProtected) {
this.nativeViewProtected.layout(left, top, right, bottom);
Expand Down Expand Up @@ -727,6 +728,9 @@ export class View extends ViewCommon {
this._setMinHeightNative(this.minHeight);
}
}
[transitionNameProperty.setNative](value: string) {
(android.support.v4.view.ViewCompat as any).setTransitionName(this.nativeViewProtected, value);
}

_redrawNativeBackground(value: android.graphics.drawable.Drawable | Background): void {
if (value instanceof Background) {
Expand Down
8 changes: 7 additions & 1 deletion tns-core-modules/ui/core/view/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ export abstract class View extends ViewBase {
*/
automationText: string;

/**
* Gets or sets the transition name of the view.
*/
transitionName: string;

/**
* Gets or sets the X component of the origin point around which the view will be transformed. The deafault value is 0.5 representing the center of the view.
*/
Expand Down Expand Up @@ -653,7 +658,7 @@ export abstract class View extends ViewBase {
/**
* @private
*/
_getFragmentManager(): any; /* android.app.FragmentManager */
_getFragmentManager(): any; /* android.support.v4.app.FragmentManager */

/**
* Updates styleScope or create new styleScope.
Expand Down Expand Up @@ -763,6 +768,7 @@ export interface AddChildFromBuilder {
}

export const automationTextProperty: Property<View, string>;
export const transitionNameProperty: Property<View, string>;
export const originXProperty: Property<View, number>;
export const originYProperty: Property<View, number>;
export const isEnabledProperty: Property<View, boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function dismissSoftInput(owner: EditableTextBase): void {
if (!dismissKeyboardTimeoutId) {
dismissKeyboardTimeoutId = setTimeout(() => {
const owner = dismissKeyboardOwner && dismissKeyboardOwner.get();
const activity = (owner && owner._context) as android.app.Activity;
const activity = (owner && owner._context) as android.support.v7.app.AppCompatActivity;
const nativeView = owner && owner.nativeViewProtected;
dismissKeyboardTimeoutId = null;
dismissKeyboardOwner = null;
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/frame/activity.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if ((<any>global).__snapshot || (<any>global).__snapshotEnabled) {
}

@JavaProxy("com.tns.NativeScriptActivity")
class NativeScriptActivity extends android.app.Activity {
class NativeScriptActivity extends android.support.v7.app.AppCompatActivity {
private _callbacks: AndroidActivityCallbacks;
public isNativeScriptActivity;
constructor() {
Expand Down
8 changes: 5 additions & 3 deletions tns-core-modules/ui/frame/fragment.android.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AndroidFragmentCallbacks, setFragmentCallbacks, setFragmentClass } from "./frame";

@JavaProxy("com.tns.FragmentClass")
class FragmentClass extends android.app.Fragment {
class FragmentClass extends android.support.v4.app.Fragment {
// This field is updated in the frame module upon `new` (although hacky this eases the Fragment->callbacks association a lot)
private _callbacks: AndroidFragmentCallbacks;

Expand All @@ -15,8 +15,10 @@ class FragmentClass extends android.app.Fragment {
}

public onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator {
let result = this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator);
return result;
return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator);
}
public onCreateAnimation(transit: number, enter: boolean, nextAnim: number): android.view.animation.Animation {
return this._callbacks.onCreateAnimation(this, transit, enter, nextAnim, super.onCreateAnimation);
}

public onStop(): void {
Expand Down
Loading