Problem using getLocationInWindow


#1

I have created a ListView that displays a number of teasers for articles, the user can click on a teaser and then when they go back to the listView an overlay shows up.

The overlay should be positioned according to where the teaser item is, if there is not enough space I scrollToIndex so the teaser is at the top of the screen and then find the position of a button using getLocationInWindow within the teaser.

In the FeedComponent class I store the Teaser class that the user has clicked on and when the user returns I call a method inside the Teaser class which uses the getLocationInWindow method on a Button element to find it’s Point.

The Teaser class is

export class Teaser implements OnInit {
    @Input()
    index: number;

    @ViewChild('contextMenuBtn')
    contextMenuBtnRef: ElementRef;
    contextMenuBtn: Button;

    constructor() {}

    ngOnInit(): void {
        this.contextMenuBtn = <Button>this.contextMenuBtnRef.nativeElement;
    }

    onTeaserTapped(): void {
        this.teaserTap.emit(this);
    }

    getHideArticleBtnPosition(): Point {
        return this.contextMenuBtn.getLocationInWindow();
    }
}

Calling getHideArticleBtnPosition works as expected in iOS and the first time around on Android but returns undefined on Android when returning to the ListView and calling the method.

It still seems to have the class because I can still query index and see that it’s the correct one but all methods on the button now fail, is there any reason this should be happening?