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

TC-1398: fixed event fill for events in tableview #3872

Closed
wants to merge 2 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,31 @@ public TiUITableView getTableView()

@Override
public boolean fireEvent(String eventName, Object data) {
if (eventName.equals(TiC.EVENT_LONGPRESS) && (data instanceof HashMap)) {
if ((data instanceof HashMap) && (eventName.equals(TiC.EVENT_LONGPRESS) ||
eventName.equals(TiC.EVENT_LONGCLICK) ||
eventName.equals(TiC.EVENT_CLICK) ||
eventName.equals(TiC.EVENT_SINGLE_TAP) ||
eventName.equals(TiC.EVENT_DOUBLE_TAP) ||
eventName.equals(TiC.EVENT_SWIPE) ||
eventName.equals(TiC.EVENT_TOUCH_START) ||
eventName.equals(TiC.EVENT_TOUCH_CANCEL) ||
eventName.equals(TiC.EVENT_TOUCH_END))) {

// The data object may already be in use by the runtime thread
// due to a child view's event fire. Create a copy to be thread safe.
@SuppressWarnings("unchecked")
KrollDict dataCopy = new KrollDict((HashMap<String, Object>) data);
double x = dataCopy.getDouble(TiC.PROPERTY_X);
double y = dataCopy.getDouble(TiC.PROPERTY_Y);
int index = getTableView().getTableView().getIndexFromXY(x, y);
if (index != -1) {
Item item = getTableView().getTableView().getItemAtPosition(index);
TableViewRowProxy.fillClickEvent(dataCopy, getTableView().getModel(), item);
data = dataCopy;
KrollDict dataCopy = new KrollDict((HashMap<String, Object>)data);

TiViewProxy source = (TiViewProxy)dataCopy.get(TiC.EVENT_PROPERTY_SOURCE);
TiUIView view = source.peekView();
if (view != null && view.getNativeView() != null)
{
int index = getTableView().getTableView().getPositionForView(view.getNativeView());
if (index != -1) {
Item item = getTableView().getTableView().getItemAtPosition(index);
TableViewRowProxy.fillClickEvent(dataCopy, getTableView().getModel(), item);
data = dataCopy;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ public void enableCustomSelector() {
public Item getItemAtPosition(int position) {
return viewModel.getViewModel().get(adapter.index.get(position));
}

public int getPositionForView(View view) {
int result = -1;
try {
result = listView.getPositionForView(view);
} catch(NullPointerException e){

}
return result;
}

public int getIndexFromXY(double x, double y) {
int bound = listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
Expand Down