[TIMOB-16905] Android: ScrollView automatically scrolls to TextField after click on switch or picker selection
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | In Progress |
Resolution | Unresolved |
Affected Version/s | Release 3.2.2 |
Fix Version/s | n/a |
Components | Android |
Labels | android, focus, picker, scrollview, switch, textfield |
Reporter | Mark Mokryn |
Assignee | Maggie Chen |
Created | 2014-04-25T17:56:33.000+0000 |
Updated | 2017-09-11T13:08:29.000+0000 |
Description
See code example below. Clicking on the switch, or making a picker selection causes the ScrollView to scroll back to the TextField, with apparently no way to prevent this behavior.
var win = Ti.UI.createWindow({
windowSoftInputMode: Ti.UI.Android.SOFT_INPUT_STATE_ALWAYS_HIDDEN,
backgroundColor: 'black'});
var scrollview = Ti.UI.createScrollView({
top:'0dp',
scrollType: 'vertical',
width: Ti.UI.FILL,
contentHeight: 'auto',
contentWidth: 'auto',
layout: 'vertical',
showVerticalScrollIndicator: true,
scrollingEnabled: true});
var textfield = Ti.UI.createTextField({top: 10, right: 10, left: 10});
scrollview.add(textfield);
var Switch = Ti.UI.createSwitch({
top: '2000dp'
});
scrollview.add(Switch);
var picker = Ti.UI.createPicker({
top:'20dp'
});
var data = [];
data[0]=Ti.UI.createPickerRow({title:'Bananas'});
data[1]=Ti.UI.createPickerRow({title:'Strawberries'});
data[2]=Ti.UI.createPickerRow({title:'Mangos'});
data[3]=Ti.UI.createPickerRow({title:'Grapes'});
picker.add(data);
picker.selectionIndicator = true;
scrollview.add(picker);
win.add(scrollview);
win.open();
I reduced top to 100dp for Switch to force all three controls to be on the same screen. I noticed that TextField is always focused even when you click on Switch or Picker. It gives the impression of auto scrolling when these controls are not on the same screen. Is this the behavior you are seeing as well?
Yup. I don't think users mind if the cursor stays in the TextField. The issue is however that the screen jumps back to the TextField as soon as the switch or picker are clicked, which is a real problem.
Moving this ticket to engineering as I can reproduce this issue with the provided test case.
BTW - the issue does not occur on Button elements. I have seen it on Switch and Picker, perhaps it occurs on other elements too.
Issue reproduces Titanium Studio, build: 3.3.0.201407100905 Titanium SDK version 3.3.0.GA CLI version 3.3.0, device: HTC Desire X (HT35XLY01791) Targeting Android SDK: 20
I tried this with a native android implementation and the behavior is similar. The textfield is focused and after pressing the switch, it will go to the textfield (or edittext) by scrolling to it. I tested it with a scenario as follows in a native app: EditText at the top. Switch in the middle. EditText at the bottom. Case 1: Touch EditText at the bottom. Scroll to the middle to toggle the Switch. The screen will automatically scroll to the bottom to focus on the EditText at the bottom. Case 2: Touch EditText at the top. Scroll to the middle to toggle the Switch. The screen will automatically scroll to the top to focus on the EditText at the top.