Skip to content

Commit

Permalink
feat(android): add Ti.UI.Window.closed property
Browse files Browse the repository at this point in the history
Fixes TIMOB-27711
  • Loading branch information
sgtcoolguy committed Jun 22, 2020
1 parent 6a6fda4 commit 1c66a80
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import ti.modules.titanium.android.AndroidModule;
import android.app.Activity;
import android.support.annotation.NonNull;

@Kroll.proxy(creatableInModule = AndroidModule.class)
public class TiActivityWindowProxy extends TiWindowProxy
Expand All @@ -35,7 +36,7 @@ public void setView(TiUIView view)
}

@Override
protected void handleClose(KrollDict options)
protected void handleClose(@NonNull KrollDict options)
{
Log.d(TAG, "handleClose", Log.DEBUG_MODE);
fireEvent("close", null);
Expand All @@ -45,7 +46,8 @@ protected void handleClose(KrollDict options)
}

releaseViews();
opened = false;
opened =
false; // FIXME: This will lead to odd case of a close listener querying isCLosed and getting false! Set to false above? fire event after?
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.content.Intent;
import android.os.Message;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Expand Down Expand Up @@ -496,7 +497,7 @@ protected void handlePostOpen()
}

@Override
protected void handleClose(KrollDict options)
protected void handleClose(@NonNull KrollDict options)
{
Log.d(TAG, "handleClose: " + options, Log.DEBUG_MODE);

Expand All @@ -516,6 +517,8 @@ protected void handleClose(KrollDict options)
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
activity.finish();
}

// TODO: Does this ever fire the close event?!
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Message;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -180,7 +181,7 @@ protected void handleOpen(KrollDict options)
}

@Override
protected void handleClose(KrollDict options)
protected void handleClose(@NonNull KrollDict options)
{
// Fetch this window's "exitOnClose" property setting.
boolean exitOnClose = (TiActivityWindows.getWindowCount() <= 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import androidx.core.app.ActivityOptionsCompat;
import androidx.core.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.view.View;
Expand Down Expand Up @@ -131,11 +132,17 @@ public void open(@Kroll.argument(optional = true) Object arg)
handleOpen(options);
}

@Kroll.getProperty(name = "closed")
public boolean isClosed()
{
return !opened && !opening;
}

@SuppressWarnings("unchecked")
@Kroll.method
public void close(@Kroll.argument(optional = true) Object arg)
{

// TODO: if not opened, ignore? We do this in WindowProxy subclass, but not the other two...
KrollDict options = null;
TiAnimation animation = null;

Expand All @@ -153,6 +160,7 @@ public void close(@Kroll.argument(optional = true) Object arg)
}

handleClose(options);
// FIXME: Maybe fire the close event here and set opened to false as well, rather than leaving to subclasses?
}

public void closeFromActivity(boolean activityIsFinishing)
Expand Down Expand Up @@ -465,7 +473,7 @@ public KrollDict getSafeAreaPadding()
}

protected abstract void handleOpen(KrollDict options);
protected abstract void handleClose(KrollDict options);
protected abstract void handleClose(@NonNull KrollDict options);
protected abstract Activity getWindowActivity();

/**
Expand Down

0 comments on commit 1c66a80

Please sign in to comment.