Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3155] Android: Tableview missing scrollToTop method

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:01:03.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-11
ComponentsAndroid
Labelsandroid, feature, release-1.7.0, reported-1.5.1, rplist
ReporterDon Thorp
AssigneeDon Thorp
Created2011-04-15T03:38:10.000+0000
Updated2011-04-17T02:01:03.000+0000

Description

See http://developer.appcelerator.com/helpdesk/view/73731">Helpdesk 73731

Attachments

FileDateSize
app.js2011-04-15T03:38:11.000+0000722

Comments

  1. hal 2011-04-15

    Note that scrollToIndex(), which works on android without issue, can in some cases be used as a substitute for scrollToTop().

    In case you need it, the following simple usecase reproduces the issue for scrollToTop():

       var win = Ti.UI.createWindow({
           backgroundColor: 'white',
           exitOnClose:true
       });
       
       var data = [];
       
       for(var i=0;i<25;i++){
           Ti.API.info('Loop iteration '+i);
           var thisRow = Ti.UI.createTableViewRow({
               title:'Row '+i
           });
           
           data.push(thisRow);
           
           if(i === 24){
               thisRow.addEventListener('click', function(){
                   tableview.scrollToTop(0,{animated:true});
               });
           }
       }
       
       
       var tableview = Ti.UI.createTableView({
           data:data
       });
       
       tableview.addEventListener('click', function(e)
       {
           // event data
           var index = e.index;
           var row = e.row;
           var rowdata = e.rowData;
           Ti.API.info('Table View: row = ' + row + ', index = ' + index);
       });
       
       win.add(tableview);
       win.open();
       

    This produces the following exception:

         762         KeyCharacterMap  W  No keyboard for id 0
         762         KeyCharacterMap  W  Using default keymap: /system/usr/keychars/qwerty.kcm.bin
         762           KrollCallback  E  (kroll$1) [63461,66611] ECMA Error evaluating source, invocation: [callMethod UI.TableViewRow.UI.TableVi
                                         ewRow:event:click null], message: TypeError: Cannot find function scrollToTop in object [Ti.UI.TableView
                                         ]. (app://app.js#70)
         762           KrollCallback  E  org.mozilla.javascript.EcmaError: TypeError: Cannot find function scrollToTop in object [Ti.UI.TableView
                                         ]. (app://app.js#70)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3761)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3739)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3767)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3786)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3850)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2343)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2310)
         762           KrollCallback  E    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1524)
         762           KrollCallback  E    at script(app://app.js:70)
         762           KrollCallback  E    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
         762           KrollCallback  E    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
         762           KrollCallback  E    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
         762           KrollCallback  E    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
         762           KrollCallback  E    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
         762           KrollCallback  E    at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:132)
         762           KrollCallback  E    at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:156)
         762           KrollCallback  E    at android.os.Handler.handleCallback(Handler.java:587)
         762           KrollCallback  E    at android.os.Handler.dispatchMessage(Handler.java:92)
         762           KrollCallback  E    at android.os.Looper.loop(Looper.java:123)
         762           KrollCallback  E    at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:73)
         762               TiContext  E  (kroll$1) [17,66628] Rhino Error: app://app.js:70,0
         762               TiContext  E  (kroll$1) [4,66632]  Message: TypeError: Cannot find function scrollToTop in object [Ti.UI.TableView]. (
                                         app://app.js#70)
         762               TiContext  E  (kroll$1) [8,66640]  Source: null
       
  2. hal 2011-04-15

    Note, the user has provided a good explanation of why this would be useful, and how the functionality works on iOS:

    "The scenario goes like this: I have a tableviewrow with a textfield in it. When the textfield receives focus, the keyboard slides up and hence I need that row to slide up as well and be visible. I could do this on the iPhone using scrollToTop. ScrollToIndex only makes sure that the row with the given index is visible on screen. However, it does not take the keyboard sliding into consideration. Hence, even though the row is technically visible, it could be still be hidden behind the keyboard."

  3. Opie Cyrus 2011-04-15

    (from [e49e01936563ad375adbaa9db28ed86696e1638c]) [#3155 state:fixed-in-qa] added scrollToTop method for Table View

    Added scrollToTop method for Table View in Android
    https://github.com/appcelerator/titanium_mobile/commit/e49e01936563ad375adbaa9db28ed86696e1638c"> https://github.com/appcelerator/titanium_mobile/commit/e49e01936563...

  4. Opie Cyrus 2011-04-15

    Please verify fix with attached app.js. If you click on row 5, you should see row 13 scroll to the top of the table view.

  5. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/17/11 10:02 630a276) on
    iPad 4.3
    Simulator 4.1
    iPhone4 4.3
    Clicking on row 5 just slightly moves it does not bring row 13 to top

    Tested with Titanium SDK version: 1.7.0 (03/17/11 10:02 630a276) on
    Nexus S 2.3.2 puts row 13 into the viewable area but not to top
    Emulator 2.1 puts row 13 to top
    Emulator 2.1 WVGA800 puts row 13 into the viewable area but not to top

  6. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/17/11 10:02 630a276) on
    Nexus S 2.3.2 puts row 13 into the viewable area but not to top --- The screen is high density so it can display a lot more in the view, and having only 24 items bringing 13 to the top will cause white space below which is not allowed. Modifying the test to consist of 45 works as expected.

JSON Source