Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-26662] Android: TableViewRow bugs #10542

Merged
merged 12 commits into from
Feb 11, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem;
import android.app.Activity;
import android.os.Message;
import android.view.View;

// clang-format off
@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
Expand Down Expand Up @@ -171,6 +173,16 @@ public void remove(TiViewProxy control)
}
}

@Override
public KrollDict getRect()
{
View v = null;
if (tableViewItem != null) {
v = tableViewItem.getContentView();
}
return getViewRect(v);
}

public void setTableViewItem(TiTableViewRowProxyItem item)
{
this.tableViewItem = item;
Expand Down Expand Up @@ -201,9 +213,14 @@ public boolean handleMessage(Message msg)
if (tableViewItem != null) {
tableViewItem.setRowData(this);
// update/refresh table view when a row's data changed.
TiUITableView table = getTable().getTableView();
table.setModelDirty();
table.updateView();
TableViewProxy proxy = getTable();
if (proxy != null) {
TiUITableView table = (TiUITableView) proxy.peekView();
garymathews marked this conversation as resolved.
Show resolved Hide resolved
if (table != null) {
table.setModelDirty();
table.updateView();
}
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
} else {
h = Math.max(minRowHeight, height.getAsPixels(this));
}
// Make sure the height is greater than 1 (not 0 since image views default to 1)
if (hasChildView && h > 1) {
content.getLayoutParams().height = h;
}
garymathews marked this conversation as resolved.
Show resolved Hide resolved

if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Row content measure (" + adjustedWidth + "x" + h + ")", Log.DEBUG_MODE);
Expand Down Expand Up @@ -656,6 +652,11 @@ public Drawable getSelectorDrawable()
return selectorDrawable;
}

public TiCompositeLayout getContentView()
{
return this.content;
}

@Override
public void release()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,31 +273,34 @@ public boolean handleMessage(Message msg)
public KrollDict getRect()
// clang-format on
{
KrollDict d = new KrollDict();
View v = null;
if (view != null) {
View v = view.getOuterView();
if (v != null) {
int position[] = new int[2];
v.getLocationInWindow(position);

TiDimension nativeWidth = new TiDimension(v.getWidth(), TiDimension.TYPE_WIDTH);
TiDimension nativeHeight = new TiDimension(v.getHeight(), TiDimension.TYPE_HEIGHT);
TiDimension nativeLeft = new TiDimension(position[0], TiDimension.TYPE_LEFT);
TiDimension nativeTop = new TiDimension(position[1], TiDimension.TYPE_TOP);
TiDimension localLeft = new TiDimension(v.getX(), TiDimension.TYPE_LEFT);
TiDimension localTop = new TiDimension(v.getY(), TiDimension.TYPE_TOP);
v = view.getOuterView();
}
return getViewRect(v);
}

// TiDimension needs a view to grab the window manager, so we'll just use the decorview of the current window
View decorView = TiApplication.getAppRootOrCurrentActivity().getWindow().getDecorView();
if (decorView != null) {
d.put(TiC.PROPERTY_WIDTH, nativeWidth.getAsDefault(decorView));
d.put(TiC.PROPERTY_HEIGHT, nativeHeight.getAsDefault(decorView));
d.put(TiC.PROPERTY_X, localLeft.getAsDefault(decorView));
d.put(TiC.PROPERTY_Y, localTop.getAsDefault(decorView));
d.put(TiC.PROPERTY_X_ABSOLUTE, nativeLeft.getAsDefault(decorView));
d.put(TiC.PROPERTY_Y_ABSOLUTE, nativeTop.getAsDefault(decorView));
}
}
protected KrollDict getViewRect(View v)
{
KrollDict d = new KrollDict();
if (v != null) {
int position[] = new int[2];
v.getLocationInWindow(position);

TiDimension nativeWidth = new TiDimension(v.getWidth(), TiDimension.TYPE_WIDTH);
TiDimension nativeHeight = new TiDimension(v.getHeight(), TiDimension.TYPE_HEIGHT);
TiDimension nativeLeft = new TiDimension(position[0], TiDimension.TYPE_LEFT);
TiDimension nativeTop = new TiDimension(position[1], TiDimension.TYPE_TOP);
TiDimension localLeft = new TiDimension(v.getX(), TiDimension.TYPE_LEFT);
TiDimension localTop = new TiDimension(v.getY(), TiDimension.TYPE_TOP);

// TiDimension needs a view to grab the window manager.
d.put(TiC.PROPERTY_WIDTH, nativeWidth.getAsDefault(v));
d.put(TiC.PROPERTY_HEIGHT, nativeHeight.getAsDefault(v));
d.put(TiC.PROPERTY_X, localLeft.getAsDefault(v));
d.put(TiC.PROPERTY_Y, localTop.getAsDefault(v));
d.put(TiC.PROPERTY_X_ABSOLUTE, nativeLeft.getAsDefault(v));
d.put(TiC.PROPERTY_Y_ABSOLUTE, nativeTop.getAsDefault(v));
}
if (!d.containsKey(TiC.PROPERTY_WIDTH)) {
d.put(TiC.PROPERTY_WIDTH, 0);
Expand Down
59 changes: 59 additions & 0 deletions tests/Resources/ti.ui.tableview.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2015-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.TableView', function () {
var win;

this.timeout(5000);

afterEach(function (done) {
if (win) {
win.close();
}
win = null;

// timeout to allow window to close
setTimeout(() => {
done();
}, 500);
});

it.iosBroken('resize row with Ti.UI.SIZE on content height change', function (finish) {
var heights = [ 100, 200, 50 ];
var tableView = Ti.UI.createTableView({});
var row = Ti.UI.createTableViewRow({
height: Ti.UI.SIZE,
width: Ti.UI.FILL
});
var view = Ti.UI.createView({
height: heights.pop(),
backgroundColor: 'red'
});
row.add(view);
tableView.setData([ row ]);
tableView.addEventListener('postlayout', function onPostLayout() {
console.error('postlayout', row.rect.height, view.rect.height);
should(row.rect.height).be.eql(view.rect.height);
if (!heights.length) {
tableView.removeEventListener('postlayout', onPostLayout);
finish();
}
view.height = heights.pop();
});

win = Ti.UI.createWindow({
backgroundColor: 'blue'
});

win.add(tableView);
win.open();
});
});