Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListView: Inconsistency retrieving bindingContext in tap handler #940

Closed
tjvantoll opened this issue Oct 14, 2015 · 3 comments · Fixed by #950
Closed

ListView: Inconsistency retrieving bindingContext in tap handler #940

tjvantoll opened this issue Oct 14, 2015 · 3 comments · Fixed by #950
Assignees
Milestone

Comments

@tjvantoll
Copy link
Contributor

This is a small issue that has tripped me up before, and which was also reported to me on Twitter. The syntax to get the bindingContext in a list view item's tap handler varies based on the type of element you use. Here's a short example:

<Page loaded="loaded">
    <ListView items="{{ myList }}">
        <ListView.itemTemplate>
            <StackLayout>
                <Button tap="buttonTap" text="Hi, I'm a button" />
                <Label tap="labelTap" text="Hi, I'm a label" />
            </StackLayout>
        </ListView.itemTemplate>
    </ListView>
</Page>
var observableModule = require("data/observable");
var observableArrayModule = require("data/observable-array");

var pageData = new observableModule.Observable({
    myList: new observableArrayModule.ObservableArray(["foo", "bar"])
});

exports.loaded = function(args) {
    var page = args.object;
    page.bindingContext = pageData;
};

exports.buttonTap = function(args) {
    console.log(args.object.bindingContext);
};
exports.labelTap = function(args) {
    console.log(args.view.bindingContext)
};

The thing to notice here is that buttonTap uses args.object.bindingContext, whereas labelTap uses args.view.bindingContext to get a reference to the same data.

It seems like the API should be the same regardless of what type of UI component you use. A consistent approach would also make it far easier to share code.

@enchev
Copy link
Contributor

enchev commented Oct 15, 2015

Hey TJ,

This comes from the fact that the Button tap is event while the Label tap is gesture. We realized that both APIs can be merged and this is already done in our 1.4 release.

Can you try args.object.bindingContext for the Label if you use 1.4?

Thanks

@tjvantoll
Copy link
Contributor Author

Thanks @enchev.

Interestingly with 1.4 using args.object.bindingContext for the Label works on Android, but does not work on iOS.

@enchev enchev self-assigned this Oct 16, 2015
@enchev enchev added this to the 1.5 (Under Review) milestone Oct 16, 2015
@enchev enchev added the done label Oct 16, 2015
@lock
Copy link

lock bot commented Aug 30, 2019

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.

@lock lock bot locked and limited conversation to collaborators Aug 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants