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

Change how to generate IDs #31

Open
cs-bruno-silva opened this issue May 11, 2018 · 2 comments
Open

Change how to generate IDs #31

cs-bruno-silva opened this issue May 11, 2018 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@cs-bruno-silva
Copy link
Contributor

We're currently using String.hashCode() to parse a string to a int id, but it can produce errors since Ids can't be negative.

@cs-bruno-silva cs-bruno-silva added this to the 1.3.0 milestone May 11, 2018
@cs-bruno-silva cs-bruno-silva added the bug Something isn't working label May 14, 2018
@brunodles
Copy link

brunodles commented May 15, 2018

The cause of this problem can be found on android sources, as we talked about.

This is the source code of findViewById method, explaining the reason why ids aren't negative.

public final View findViewById(int id) {
    if (id < 0) {
        return null;
    }
    return findViewTraversal(id);
}

https://android.googlesource.com/platform/frameworks/base/+/a175a5b/core/java/android/view/View.java#12583

@cs-matheus-candido
Copy link
Contributor

cs-matheus-candido commented Aug 1, 2018

Proposed solution: have an ArrayMap that will hold a String key (indicating the "resource id" name) and an Integer value holding the result of View.generateViewId(). The rest of the library can use this data structure to query the safe ids.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants