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

fix(android): crash in ListView on API 21 #13262

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -214,7 +215,9 @@ private void processProperty(String name, Object value)
? TiConvert.toTiDimension(heightString, TiDimension.TYPE_HEIGHT)
.getAsPixels((View) getNativeView().getParent()) : 0;

if (name.equals(TiC.PROPERTY_SEPARATOR_COLOR)
if (height == 0) {
this.listView.setSeparator(0, height);
} else if (name.equals(TiC.PROPERTY_SEPARATOR_COLOR)
|| properties.containsKey(TiC.PROPERTY_SEPARATOR_COLOR)) {
String colorString = properties.getString(TiC.PROPERTY_SEPARATOR_COLOR);
if (name.equals(TiC.PROPERTY_SEPARATOR_COLOR)) {
Expand All @@ -227,10 +230,12 @@ private void processProperty(String name, Object value)

} else {
final TypedArray divider = context.obtainStyledAttributes(new int[] { android.R.attr.listDivider });
final GradientDrawable defaultDrawable = (GradientDrawable) divider.getDrawable(0);
final Drawable defaultDrawable = divider.getDrawable(0);

// Set platform default separator.
defaultDrawable.setSize(0, height);
if (defaultDrawable instanceof GradientDrawable) {
((GradientDrawable) defaultDrawable).setSize(0, height);
}
this.listView.setSeparator(defaultDrawable);
divider.recycle();
}
Expand Down
4 changes: 3 additions & 1 deletion apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ properties:
description: |
Height of the ListView separator, in platform-specific units. If undefined, default native height will be used.
Numerical inputs are treated as pixels. For example, 3 and "3px" are equivalent.
On Android API < 23 you must specify <Titanium.UI.ListView.separatorStyle> and
<Titanium.UI.ListView.separatorColor> for this property to work.
type: [String, Number]
since: "4.1.0"
platforms: [android]
Expand Down Expand Up @@ -1367,8 +1369,8 @@ examples:
{properties: { title: 'Carrots'}},
{properties: { title: 'Potatoes'}},
];
sections.push(vegSection);
var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables', items: vegDataSet});
sections.push(vegSection);

listView.sections = sections;
win.add(listView);
Expand Down