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-26168] Android: Fix initializing of scrollbars #10142

Merged
merged 4 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="horizontal"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"/>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;
import org.xmlpull.v1.XmlPullParser;

import ti.modules.titanium.ui.RefreshControlProxy;

Expand All @@ -28,6 +30,8 @@
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.util.Xml;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -51,6 +55,9 @@ public class TiUIScrollView extends TiUIView
private boolean isScrolling = false;
private boolean isTouching = false;

private static int verticalAttrId = -1;
private static int horizontalAttrId = -1;

public class TiScrollViewLayout extends TiCompositeLayout
{
private static final int AUTO = Integer.MAX_VALUE;
Expand Down Expand Up @@ -315,14 +322,34 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
}
}

// TIMOB-26168: if 'android:scrollbars' is not defined then our scrollbars will never be initialized
// so we do this our selves
private AttributeSet getAttributeSet(Context context, int resourceId)
{
AttributeSet attr = null;
try {
XmlPullParser parser = context.getResources().getXml(resourceId);
try {
parser.next();
parser.nextTag();
} catch (Exception e) {
// ignore...
}
attr = Xml.asAttributeSet(parser);
} catch (Exception e) {
// ignore...
}
return attr;
}

// same code, different super-classes
private class TiVerticalScrollView extends NestedScrollView
{
private TiScrollViewLayout layout;

public TiVerticalScrollView(Context context, LayoutArrangement arrangement)
{
super(context);
super(context, getAttributeSet(context, verticalAttrId));

// TIMOB-25359: allow window to re-size when keyboard is shown
if (context instanceof TiBaseActivity) {
Expand Down Expand Up @@ -475,7 +502,7 @@ private class TiHorizontalScrollView extends HorizontalScrollView implements Nes

public TiHorizontalScrollView(Context context, LayoutArrangement arrangement)
{
super(context);
super(context, getAttributeSet(context, horizontalAttrId));
setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
setScrollContainer(true);

Expand Down Expand Up @@ -690,6 +717,17 @@ public TiUIScrollView(TiViewProxy proxy)
super(proxy);
getLayoutParams().autoFillsHeight = true;
getLayoutParams().autoFillsWidth = true;

try {
if (verticalAttrId == -1) {
verticalAttrId = TiRHelper.getResource("xml.titanium_ui_vertical_nested_scrollview");
}
if (horizontalAttrId == -1) {
horizontalAttrId = TiRHelper.getResource("xml.titanium_ui_horizontal_nested_scrollview");
}
} catch (Exception e) {
Log.w(TAG, "could not load NestedScrollView attributes");
}
}

@Override
Expand Down