Skip to content

Listpicker width does not compute properly. #2985

Closed

Description

@davecoffin

When displaying a list picker on iOS, the width does not always compute properly. The ListPicker element is wider than the actual content.

I have a component that shows a listpicker, the xml is:

<GridLayout loaded="onLoad" visibility="{{showPicker ? 'visible' : 'collapsed'}}">
    <StackLayout class="dimmer" id="dimmer"/>
    <GridLayout rows="*, 250, *" id="listpicker_holder">
        <ListPicker id="list_picker" row="1" colSpan="3" style="background-color: pink;" width="100%" visibility="{{showListPicker ? 'visible' : 'collapsed'}}"/>
    </GridLayout>
</GridLayout>

Here's a video of what it looks like: https://cl.ly/hwX1

If I switch to landscape and then back, the issue is fixed.

  • CLI: 2.3.0
  • Cross-platform modules: 2.3.0
  • Runtime(s): 2.3.0
  • Plugin(s):
    "moment": "^2.14.1",
    "nativescript-background-http": "0.0.3",
    "nativescript-fonticon": "^1.1.0",
    "nativescript-iqkeyboardmanager": "^1.0.1",
    "nativescript-photoviewer": "^1.0.0",
    "nativescript-pulltorefresh": "^1.1.7",
    "nativescript-slides": "^2.1.4",
    "nativescript-telerik-ui": "^1.4.0",
    "tns-core-modules": "^2.3.0"

Activity

  1. self-assigned this
    on Oct 31, 2016
  2. tsonevn commented on Oct 31, 2016

    @tsonevn
    Contributor

    Hi @davecoffin,
    Thank you for reporting this issue,
    I investigated this behavior with displaying the ListPicker in iOS and found several problems. The first one is that ListPicker resizing on iOS is not supported. The ListPicker is a common abstraction over iOS UIPickerView, underlying native iOS component is designed to used the entire width of the screen. This behavior is iOS specific and has been described in issue #314.
    The second problem that I found is that, when the ListPicker main container visibility property is set to collapsed in Page Initializing, the ListPicker width will not be set properly while setting visibility to visible state.
    Workaround:

    main-page.xml

    <Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
      <GridLayout>
        <StackLayout>
          <Label text="Tap the button" class="title"/>
          <Button text="TAP" tap="onTap" />
          <Label text="{{ message }}" class="message" textWrap="true"/>
        </StackLayout>
    
          <GridLayout style="background-color: pink;" rows="auto *" id="listpicker_holder" visibility="{{showListPicker ? 'visible' : 'collapsed'}}">
              <Button text="Close" tap="onTap" row="0" />
              <StackLayout row="1">
                  <ListPicker id="list_picker"  items="{{ options }}" />
              </StackLayout>
    
    
          </GridLayout>
      </GridLayout>
    </Page>
    

    main-page.ts

    import { Page } from 'ui/page';
    import { HelloWorldModel } from './main-view-model';
    import { setTimeout } from "timer"
    
    // Event handler for Page "navigatingTo" event attached in main-page.xml
    var listPickerVisibility = false;
    var newobservable;
    export function navigatingTo(args: EventData) {
      // Get the event sender
      let page = <Page>args.object;
      let array = ["options1", "options2", "options3"];
      newobservable = new Observable();
      newobservable.set("showListPicker", true);
      newobservable.set("options", array);
      setTimeout(function(){
        newobservable.set("showListPicker", listPickerVisibility);
      }, 1)
      page.bindingContext = newobservable;
    }
    
    export function onTap(){
      listPickerVisibility = !listPickerVisibility;
      newobservable.set("showListPicker", listPickerVisibility);
    }
    

    Hope this will help.

  3. davecoffin commented on Oct 31, 2016

    @davecoffin
    ContributorAuthor

    Thanks @tsonevn, but your xml doesnt make any difference unfortunately. Here's what it looks like (same exact problem): https://cl.ly/hxF3

  4. tsonevn commented on Oct 31, 2016

    @tsonevn
    Contributor

    Hi @davecoffin,
    Excuse me for my mistake,
    I researched further the problem and found that the problem has been caused due to setting visibility to collapsed on Page initializing. I also updated the workaround in my previous comment.

  5. davecoffin commented on Oct 31, 2016

    @davecoffin
    ContributorAuthor

    Thanks! Btw, this also appears to happen if the container is set to collapsed. The only way I could truly get around this is by hiding it using opacity=0.

  6. removed their assignment
    on Nov 1, 2016
  7. added this to the milestone on Dec 5, 2016
  8. lock commented on Aug 28, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  9. locked and limited conversation to collaborators on Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions