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

support customize platformView theme #7236

Closed
wants to merge 1 commit into from
Closed

support customize platformView theme #7236

wants to merge 1 commit into from

Conversation

SupSaiYaJin
Copy link
Contributor

This is necessary when need a translucent AndroidView to make the Flutter UI visible below an AndroidView.

@matthew-carroll
Copy link
Contributor

I'm going to leave this review for @amirh because I'm not familiar with the current architecture or possible implications of this change.

@SupSaiYaJin
Copy link
Contributor Author

@amirh any updates?

@zhugogogo
Copy link

@xster pls check this pr?

* @return A style resource describing the theme to use for the window.
*/
@StyleRes
protected int getPresentationTheme() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really know how this works.

Though it seems a bit unfortunate to create this parallel mechanism to side-load this. Can it not be passed via args from the Flutter side and then use context.setTheme or something instead?

@matthew-carroll
Copy link
Contributor

@SupSaiYaJin can you provide a screenshot or a mockup of what you're trying to achieve?

@SupSaiYaJin
Copy link
Contributor Author

SupSaiYaJin commented Apr 8, 2019

@matthew-carroll
There is a fullscreen AndroidView covering on other widgets.
Here is the screenshot of use default theme, the AndroidView is opaque. Widgets below it are covered and invisible.
Lark20190408-112612
Here is the screenshot of using android.R.style.Theme_Translucent_NoTitleBar_Fullscreen for presentation theme, The AndroidView becomes transparent. Widgets below it can be shown.
Lark20190408-112616

@matthew-carroll
Copy link
Contributor

@SupSaiYaJin I'm not sure what your screenshots are trying to show. Are those screenshots of what you currently have? or are they mockups of what you're trying to achieve? Are part of them Flutter and part of them Android?

@SupSaiYaJin
Copy link
Contributor Author

SupSaiYaJin commented Apr 10, 2019

@SupSaiYaJin I'm not sure what your screenshots are trying to show. Are those screenshots of what you currently have? or are they mockups of what you're trying to achieve? Are part of them Flutter and part of them Android?

@matthew-carroll
Here is a simple example:
Dart:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("TestAndroidView"),
        ),
        body: Stack(
          children: <Widget>[
            Container(color: Colors.red,),
            Center(
              child: SizedBox(
                height: 100,
                child: AndroidView(
                  viewType: "test",
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

Java:

  static class TestTextView implements PlatformView {

      TextView mTextView;

      TestTextView(Context context) {
          mTextView = new TextView(context);
          mTextView.setText("AndroidView Test Text");
          mTextView.setTextSize(32);
      }

      @Override
      public View getView() {
          return mTextView;
      }

      @Override
      public void dispose() {

      }
  }

Use default theme:
image

Use transparent theme:

        @Override
        public int getPresentationTheme() {
            return android.R.style.Theme_Translucent_NoTitleBar_Fullscreen;
        }

image

@SupSaiYaJin
Copy link
Contributor Author

@matthew-carroll Any suggestions? Did I describe it clearly?😁

@matthew-carroll
Copy link
Contributor

Thanks @SupSaiYaJin that helps.

Does the transparent background really require a custom theme? Can't you just setBackground() on the View to get the same effect?

@SupSaiYaJin
Copy link
Contributor Author

Thanks @SupSaiYaJin that helps.

Does the transparent background really require a custom theme? Can't you just setBackground() on the View to get the same effect?

No, it didn't work, cause the Window of Presentation is opaque.

@SupSaiYaJin
Copy link
Contributor Author

Thanks @SupSaiYaJin that helps.

Does the transparent background really require a custom theme? Can't you just setBackground() on the View to get the same effect?

The View is already transparent. But the Window isn't.

@matthew-carroll
Copy link
Contributor

@amirh what do you think is the right approach here? Should platform views support theming, or is there some other way that transparency should be supported?

@cbracken
Copy link
Member

@amirh have you had time to have a look at this? If so, any feedback?

@AndreaMiotto
Copy link

@SupSaiYaJin how can I bring your code to my flutter project? I can't find where the flutter engine is stored

@dfavaro
Copy link

dfavaro commented Jun 7, 2019

@amirh issue still present. Any temporary workaround? Thanks

@bi-a
Copy link

bi-a commented Jun 10, 2019

@amirh can you please review this code for accept the merge request?

@AndreaMiotto
Copy link

@amirh when do you think this could be fixed? I have a sprint review with the client next week and I have to bring an answer for this problem.

cc @matthew-carroll

@amirh
Copy link
Contributor

amirh commented Jul 15, 2019

I apologize for the long delay on this.

It seems to me like it would make sense to just always have the VD's window be translucent. Normally in Android you'd only do it when needed in order to save a composition step between windows, but since the VD has just one window there should be no cost for always keeping that window translucent(which has a side effect of preserving alpha which is what we really want here).

I sent #9828 which is a simplified version of this PR to do that.

Thank you again for bringing this up and finding the solution!

@SupSaiYaJin
Copy link
Contributor Author

@amirh I found that touch events would be misaligned the height of the status bar in some devices with notch screen such as Xiaomi 8. Use android.R.style.Theme_Panel will resolve this.

@amirh
Copy link
Contributor

amirh commented Jul 16, 2019

@SupSaiYaJin thanks for the quick report!
I sent #9849 as a speculative fix.

@amirh
Copy link
Contributor

amirh commented Jul 25, 2019

Closing this PR as the issue was addressed by #9849

@amirh amirh closed this Jul 25, 2019
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.

10 participants