Skip to content

Commit

Permalink
fix(android): touchFeedback support for ListView and TableView (#12440)
Browse files Browse the repository at this point in the history
Fixes TIMOB-28329, TIMOB-27504
  • Loading branch information
garymathews authored and sgtcoolguy committed Mar 12, 2021
1 parent f093c15 commit 5e77724
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
android:id="@+id/titanium_ui_listview_holder_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:addStatesFromChildren="true"/>

<ImageView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:addStatesFromChildren="true"
android:foreground="?attr/selectableItemBackgroundBorderless">
android:addStatesFromChildren="true">

<ImageView
android:id="@+id/titanium_ui_tableview_holder_left_image"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@
propertyAccessors = {
TiC.PROPERTY_EDITABLE,
TiC.PROPERTY_EDITING,
TiC.PROPERTY_FILTER_ATTRIBUTE,
TiC.PROPERTY_FILTER_ANCHORED,
TiC.PROPERTY_FILTER_ATTRIBUTE,
TiC.PROPERTY_FILTER_CASE_INSENSITIVE,
TiC.PROPERTY_HEADER_TITLE,
TiC.PROPERTY_HEADER_VIEW,
TiC.PROPERTY_FOOTER_DIVIDERS_ENABLED,
TiC.PROPERTY_FOOTER_TITLE,
TiC.PROPERTY_FOOTER_VIEW,
TiC.PROPERTY_SEARCH,
TiC.PROPERTY_SEPARATOR_COLOR,
TiC.PROPERTY_SEPARATOR_STYLE,
TiC.PROPERTY_OVER_SCROLL_MODE,
TiC.PROPERTY_HEADER_DIVIDERS_ENABLED,
TiC.PROPERTY_HEADER_TITLE,
TiC.PROPERTY_HEADER_VIEW,
TiC.PROPERTY_MAX_CLASSNAME,
TiC.PROPERTY_MIN_ROW_HEIGHT,
TiC.PROPERTY_MOVABLE,
TiC.PROPERTY_MOVING,
TiC.PROPERTY_HEADER_DIVIDERS_ENABLED,
TiC.PROPERTY_FOOTER_DIVIDERS_ENABLED,
TiC.PROPERTY_MAX_CLASSNAME,
TiC.PROPERTY_OVER_SCROLL_MODE,
TiC.PROPERTY_REFRESH_CONTROL,
TiC.PROPERTY_SCROLLABLE,
TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR
TiC.PROPERTY_SEARCH,
TiC.PROPERTY_SEPARATOR_COLOR,
TiC.PROPERTY_SEPARATOR_STYLE,
TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR,
TiC.PROPERTY_TOUCH_FEEDBACK,
TiC.PROPERTY_TOUCH_FEEDBACK_COLOR
}
)
public class TableViewProxy extends RecyclerViewProxy
Expand All @@ -64,6 +66,7 @@ public TableViewProxy()

defaultValues.put(TiC.PROPERTY_OVER_SCROLL_MODE, 0);
defaultValues.put(TiC.PROPERTY_SCROLLABLE, true);
defaultValues.put(TiC.PROPERTY_TOUCH_FEEDBACK, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;

import ti.modules.titanium.ui.widget.TiView;
import ti.modules.titanium.ui.widget.tableview.TableViewHolder;
import ti.modules.titanium.ui.widget.tableview.TiTableView;
Expand Down Expand Up @@ -501,5 +503,19 @@ public void setNativeView(View view)
}
super.setNativeView(view);
}

@Override
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Prevent TiUIView from overriding `touchFeedback` effect.
return false;
}

@Override
protected boolean hasBorder(KrollDict d)
{
// Always create custom background drawable.
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiC;
Expand Down Expand Up @@ -49,6 +51,19 @@ public TiUIListView(TiViewProxy proxy)
setNativeView(listView);
}

/**
* Determine if touchFeedback can be applied to view.
*
* @param props View's property dictionary
* @return Boolean
*/
@Override
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Ignore, handled by item.
return false;
}

/**
* Get current list view instance.
*
Expand Down Expand Up @@ -222,6 +237,15 @@ public void processProperties(KrollDict d)
@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
if (key.equals(TiC.PROPERTY_TOUCH_FEEDBACK)
|| key.equals(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR)) {

// Update list items.
this.listView.update();

// Return to prevent property being handled by TiUIView.
return;
}
super.propertyChanged(key, oldValue, newValue, proxy);

processProperty(key, newValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import ti.modules.titanium.ui.RefreshControlProxy;
import ti.modules.titanium.ui.SearchBarProxy;
import ti.modules.titanium.ui.TableViewProxy;
Expand Down Expand Up @@ -49,6 +51,19 @@ public TiUITableView(TiViewProxy proxy)
setNativeView(tableView);
}

/**
* Determine if touchFeedback can be applied to view.
*
* @param props View's property dictionary
* @return Boolean
*/
@Override
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Ignore, handled by row.
return false;
}

/**
* Get current table view instance.
*
Expand Down Expand Up @@ -228,6 +243,15 @@ public void processProperties(KrollDict d)
@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
if (key.equals(TiC.PROPERTY_TOUCH_FEEDBACK)
|| key.equals(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR)) {

// Update table items.
this.tableView.update();

// Return to prevent property being handled by TiUIView.
return;
}
super.propertyChanged(key, oldValue, newValue, proxy);

processProperty(key, newValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
Expand All @@ -28,6 +31,8 @@

public class ItemTouchHandler extends ItemTouchHelper.SimpleCallback
{
private static final String TAG = "ItemTouchHandler";

private TiRecyclerViewAdapter adapter;
private RecyclerViewProxy recyclerViewProxy;
private Pair<Integer, Integer> movePair = null;
Expand Down Expand Up @@ -127,10 +132,33 @@ private Drawable getBackground(TiUIView parentView, boolean ignoreTransparent)
while (parentNativeView != null && parentBackground == null) {
parentBackground = parentNativeView.getBackground();

if (parentBackground instanceof RippleDrawable) {
final RippleDrawable rippleDrawable = (RippleDrawable) parentBackground;

if (rippleDrawable.getNumberOfLayers() > 0) {
final Drawable drawable = rippleDrawable.getDrawable(0);

// Ignore masks (ShapeDrawable).
parentBackground = drawable.getClass().equals(ShapeDrawable.class) ? null : drawable;

} else if (ignoreTransparent) {

// No layers, ignore transparent drawable.
parentBackground = null;
}
}
if (parentBackground instanceof ColorDrawable) {
final ColorDrawable colorDrawable = (ColorDrawable) parentBackground;

if (ignoreTransparent && colorDrawable.getColor() == Color.TRANSPARENT) {
if (ignoreTransparent && Color.alpha(colorDrawable.getColor()) <= 0) {

// Ignore transparent backgrounds.
parentBackground = null;
}
} else if (parentBackground instanceof PaintDrawable) {
final PaintDrawable paintDrawable = (PaintDrawable) parentBackground;

if (ignoreTransparent && Color.alpha(paintDrawable.getPaint().getColor()) <= 0) {

// Ignore transparent backgrounds.
parentBackground = null;
Expand Down Expand Up @@ -290,7 +318,9 @@ public void onChildDraw(@NonNull Canvas c,
// Determine if current background is transparent.
final boolean hasTransparentBackground = currentBackground == null
|| (currentBackground instanceof ColorDrawable
&& ((ColorDrawable) currentBackground).getColor() == Color.TRANSPARENT);
&& Color.alpha(((ColorDrawable) currentBackground).getColor()) <= 0)
|| (currentBackground instanceof PaintDrawable
&& Color.alpha(((PaintDrawable) currentBackground).getPaint().getColor()) <= 0);

if (hasTransparentBackground) {
final TiUIView parentView = recyclerViewProxy.getOrCreateView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;

import ti.modules.titanium.ui.UIModule;
import ti.modules.titanium.ui.widget.TiView;

Expand Down Expand Up @@ -677,5 +679,12 @@ public ItemView(TiViewProxy proxy)

getLayoutParams().autoFillsWidth = true;
}

@Override
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Prevent TiUIView from overriding `touchFeedback` effect.
return false;
}
}
}

0 comments on commit 5e77724

Please sign in to comment.