Skip to content

Commit

Permalink
fix(android): set ListItem properties into proxy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Jun 18, 2019
1 parent 425db87 commit 88f59d4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
ViewCompat.setImportantForAccessibility(listView, importance);
} else {
listView.setContentDescription(composeContentDescription());
listView.setContentDescription(getProxy().composeContentDescription());
}
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public void onCancel(DialogInterface dlg)
// can also be used.
ListView listView = dialog.getListView();
if (listView != null) {
listView.setContentDescription(composeContentDescription());
listView.setContentDescription(getProxy().composeContentDescription());
int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
if (proxy != null) {
Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,18 @@ public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiList
KrollDict properties = new KrollDict((HashMap) data.get(binding));
KrollDict diffProperties = viewItem.generateDiffProperties(properties);
if (!diffProperties.isEmpty()) {
if (view.getProxy() != null) {
view.getProxy().getProperties().putAll(diffProperties);
}
view.processProperties(diffProperties);
}

} else if (dataItem != null && view != null) {
KrollDict diffProperties = viewItem.generateDiffProperties(dataItem.getDefaultProperties());
if (!diffProperties.isEmpty()) {
if (view.getProxy() != null) {
view.getProxy().getProperties().putAll(diffProperties);
}
view.processProperties(diffProperties);
}
} else {
Expand Down
55 changes: 52 additions & 3 deletions android/titanium/src/java/org/appcelerator/kroll/KrollProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
*/
package org.appcelerator.kroll;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.AsyncResult;
import org.appcelerator.kroll.common.Log;
Expand All @@ -35,6 +32,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Pair;

import org.json.JSONObject;
Expand Down Expand Up @@ -978,6 +976,57 @@ public boolean doFireEvent(String event, Object data)
return krollObject.fireEvent(source, event, krollData, bubbles, reportSuccess, code, message);
}

/**
* Our view proxy supports three properties to match iOS regarding
* the text that is read aloud (or otherwise communicated) by the
* assistive technology: accessibilityLabel, accessibilityHint
* and accessibilityValue.
*
* We combine these to create the single Android property contentDescription.
* (e.g., View.setContentDescription(...));
*/
public String composeContentDescription()
{
if (properties == null) {
return null;
}

final String punctuationPattern = "^.*\\p{Punct}\\s*$";
StringBuilder buffer = new StringBuilder();
String label = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_LABEL));
String hint = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_HINT));
String value = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_VALUE));

if (!TextUtils.isEmpty(label)) {
buffer.append(label);
if (!label.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(value)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(value);
if (!value.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(hint)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(hint);
if (!hint.matches(punctuationPattern)) {
buffer.append(".");
}
}

return buffer.toString();
}

public void firePropertyChanged(String name, Object oldValue, Object newValue)
{
if (modelListener != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutParams;
import org.appcelerator.titanium.view.TiGradientDrawable.GradientType;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand All @@ -50,7 +49,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
import android.util.TypedValue;
Expand Down Expand Up @@ -2149,68 +2147,12 @@ private void applyContentDescription()
if (proxy == null || nativeView == null) {
return;
}
String contentDescription = composeContentDescription();
String contentDescription = getProxy().composeContentDescription();
if (contentDescription != null) {
nativeView.setContentDescription(contentDescription);
}
}

/**
* Our view proxy supports three properties to match iOS regarding
* the text that is read aloud (or otherwise communicated) by the
* assistive technology: accessibilityLabel, accessibilityHint
* and accessibilityValue.
*
* We combine these to create the single Android property contentDescription.
* (e.g., View.setContentDescription(...));
*/
protected String composeContentDescription()
{
if (proxy == null) {
return null;
}

KrollDict properties = proxy.getProperties();
if (properties == null) {
return null;
}

final String punctuationPattern = "^.*\\p{Punct}\\s*$";
StringBuilder buffer = new StringBuilder();
String label = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_LABEL));
String hint = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_HINT));
String value = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_VALUE));

if (!TextUtils.isEmpty(label)) {
buffer.append(label);
if (!label.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(value)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(value);
if (!value.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(hint)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(hint);
if (!hint.matches(punctuationPattern)) {
buffer.append(".");
}
}

return buffer.toString();
}

private void applyAccessibilityProperties()
{
if (nativeView != null) {
Expand Down

0 comments on commit 88f59d4

Please sign in to comment.