[SailfishDevel] Use same header item instance in multiple views

Amilcar Santos amilcar.santos at gmail.com
Sat Jul 23 23:32:59 UTC 2016


Hi Michael,

I think that it's not possible that way.. once you switch between
GridView and ListView, the SearchField loses focus (maybe force the
focus with a Timer) and probably the keyboard.

solution 1: set the SearchField outside the views and switch only the view:

Page {
  SearchField {
    id:sf
  }
  GridView {
    anchor.top: sf.bottom
  }
  ListView {
    anchor.top: sf.bottom
  }
}

solution 2: simulate the grid with a ListView with a Row :

Page {
  ListView {
    property bool gridMode: sf.text == ''
    header:   SearchField {
     id:sf
   }
   delegate: ListItem{
     Row {
       visible: gridMode
     }
     Label {
       visible: !gridMode
     }
   }
  }
}

2016-07-22 19:20 GMT+01:00 Michael Neufing <michael at neufing.org>:
> Thanks for the fast reply, Andrey!
> Maybe I don't get the idea behind your suggestion, but I can't see how that
> should help, because the reparenting is done dynamically during run-time,
> not during creation-time.
>
> Br,
> Michael
>
>
> Am 22.07.2016 19:46, schrieb Andrey Kozhevnikov:
>>
>> Wrapping your list views into loader components can probably help you :)
>>
>> ------ Исходное сообщение ------
>> От: "Michael Neufing" <michael at neufing.org>
>> Кому: devel at lists.sailfishos.org
>> Отправлено: 22.07.2016 23:43:41
>> Тема: [SailfishDevel] Use same header item instance in multiple views
>>
>>> Hi together!
>>>
>>> I am trying to use the same SearchField instance in multiple views as
>>> header item.
>>> When the page opens, a GridView is displayed with popular content. A
>>> SearchField is used as header.
>>>
>>> When the user focuses and/or writes text into the search field, the page
>>> should go into "search mode" where the GridView is hidden and a ListView
>>> with the search results is displayed.
>>> The goal is, that no screen space is wasted while scrolling. Therefore I
>>> want to have the same SearchField as header on both views.
>>>
>>> I tried to add a placeholder item into both views with the same height as
>>> the SearchField and reparent the SearchField according to the mode either
>>> into the GridView or the ListView.
>>> While that technically works (scrolling, etc), the SearchField loses it's
>>> focus during that process and the user has to re-focus the field in order to
>>> be able to type more text.
>>> Even calling "forceActiveFocus()" or setting "focus = true" on the
>>> SearchField after the reparenting does not work.
>>>
>>> Please see [1] for a code example.
>>>
>>> Can anybody help? I want to avoid that the SearchField is always visible
>>> when scrolling.
>>>
>>> Thanks.
>>>
>>> Br,
>>> Michael
>>>
>>> [1] http://pastebin.com/fhAdELHN
>>> _______________________________________________
>>> SailfishOS.org Devel mailing list
>>> To unsubscribe, please send a mail to
>>> devel-unsubscribe at lists.sailfishos.org
>>
>>
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>> To unsubscribe, please send a mail to
>> devel-unsubscribe at lists.sailfishos.org
>
> _______________________________________________
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org



-- 
Amilcar
(djditz in the mix... ;)


More information about the Devel mailing list