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

feat(android): ability to add listeners to the Capacitor WebView #4405

Merged
merged 12 commits into from
Apr 8, 2021

Conversation

carlpoole
Copy link
Member

@carlpoole carlpoole commented Mar 29, 2021

Adds the ability to register a callback to execute when certain events occur in the WebView in Capacitor. This PR includes a method to add an event when the page is finished loading. In the future this can also be used to add page error event callbacks, for instance.

Usage example: masking the view and fading it out when the web app is loaded, to hide ugly gaps in app loading

addWebViewListener(new WebViewListener() {
            @Override
            public void onPageLoaded(WebView webView) {
                fadeView.animate()
                    .alpha(0f)
                    .setDuration(duration)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            fadeView.setVisibility(View.GONE);
                        }
                    });
            }});

@carlpoole carlpoole changed the title feat(android): ability to add page load listeners to the Capacitor WebView feat(android): ability to add listeners to the Capacitor WebView Mar 31, 2021
Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation only allows to add listeners from the bridge builder. I think it should allow to add (and maybe remove) listeners after the bridge has been created too, so, in example, a plugin or some custom user code in the activity class can add new listeners

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants