Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16905] Android: ScrollView automatically scrolls to TextField after click on switch or picker selection

GitHub Issuen/a
TypeBug
PriorityMedium
StatusIn Progress
ResolutionUnresolved
Affected Version/sRelease 3.2.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, focus, picker, scrollview, switch, textfield
ReporterMark Mokryn
AssigneeMaggie Chen
Created2014-04-25T17:56:33.000+0000
Updated2017-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();

Comments

  1. Ritu Agrawal 2014-04-30

    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?
  2. Mark Mokryn 2014-04-30

    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.
  3. Ritu Agrawal 2014-05-02

    Moving this ticket to engineering as I can reproduce this issue with the provided test case.
  4. Mark Mokryn 2014-05-02

    BTW - the issue does not occur on Button elements. I have seen it on Switch and Picker, perhaps it occurs on other elements too.
  5. jithinpv 2014-08-08

    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
  6. Ashraf Abu 2014-12-18

    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.

JSON Source