Skip to content

Ability to define a custom view in ActionItem #1488

Closed

Description

@PeterStaev

Add ability for ActionItem to have a custom view associated with it, instead of using predefined icon/text. For example something like:

<ActionBar title="Something">
  <ActionBar.actionItems>
    <ActionItem ios.position="right" tap="doneTap">
        <ActionItem.actionView>
            <StackLayout>
                <Label text="Label1" backgroundColor="red"/>
                <Label text="Label2" backgroundColor="green"/>
            </StackLayout>
        </ActionItem.actionView>
    </ActionItem>
  </ActionBar.actionItems>
</ActionBar>

Implementation suggestion:
For iOS - use - (id)initWithCustomView:(UIView *)customView of the UIBarButtonItem. The catch is that in order to be able to handle tap the custom view must be a button. So the custom view must be added as a sub view to a UIButton. And then the UIButton should be passed to the initWithCustomView method.

For Android - use setActionView of MenuItem http://developer.android.com/reference/android/view/MenuItem.html#setActionView(android.view.View)

Activity

  1. enchev commented on Feb 4, 2016

    @enchev
    Contributor

    Hey @PeterStaev,

    Great suggestion! If you have already something working you can submit pull request and we will gladly help with the implementation.

  2. PeterStaev commented on Feb 4, 2016

    @PeterStaev
    ContributorAuthor

    @enchev not exactly like this, but have made something similar in a custom actionbar implementation. So will see if to plug it in the {N} code.

  3. added this to the milestone on Feb 15, 2016
  4. added
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Feb 15, 2016
  5. deanle17 commented on Feb 23, 2016

    @deanle17

    I'm sorry but I quite don't get your solution. I'm quite new to NativeScript, do you have a simple sample app about ActionBar and ActionItem customization? I would appreciate really much.

  6. modified the milestone: on Feb 24, 2016
  7. added this to the 1.7.0 milestone on Feb 24, 2016
  8. vchimev commented on Mar 2, 2016

    @vchimev
    Contributor
  9. bfattori commented on Mar 2, 2016

    @bfattori

    How about without having to use XML? I'm trying to approach the ActionBar programmatically, yet all examples start with XML.

  10. enchev commented on Mar 12, 2016

    @enchev
    Contributor

    Hey @bfattori,

    You can create some View (for example Label) and assign in to ActionItem actionView property:
    https://github.com/NativeScript/NativeScript/blob/master/ui/action-bar/action-bar.d.ts#L124

  11. added and removed
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Mar 12, 2016
  12. sitefinitysteve commented on Mar 18, 2016

    @sitefinitysteve
    Contributor

    I LOVE YOU GUYS

  13. vjoao commented on Mar 19, 2016

    @vjoao
    Contributor

    I LOVE YOU GUYS [2]

  14. chief10 commented on Aug 30, 2016

    @chief10

    Does this work with "android.position='popup' ? For me, it is not working and places the inner items outside of the popup and into the action bar.

    Here is the code for my action items -- the third one has the inner label:

     <ActionItem text="Change Layout" android.position="popup" (tap)="changeDisplayOfItems()"></ActionItem>
        <ActionItem text=" Sort by cost" android.position="popup" (tap)="sortItemsBy('size')"></ActionItem>
        <ActionItem android.position="popup" (tap)="addNewItem()">
          <Label text="Hi"></Label>
        </ActionItem>
        <ActionItem text="Account Info" (tap)="accountInfo()" android.position="popup"></ActionItem>

    But this is what is happening:

    actionitem

  15. lock commented on Aug 29, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions