简体   繁体   English

角材料CDK布局断点未涵盖Google Chrome中的iPad Pro模拟器

[英]Angular Material CDK Layout Breakpoints doesn't cover iPad pro simulator in Google Chrome

I am using BreakpointObserver to implement the responsive material design in my angular project using the following code: 我正在使用BreakpointObserver使用以下代码在我的角度项目中实现响应式材料设计:

tablet$: Observable<boolean> = this.breakpointObserver
.observe([Breakpoints.Tablet])
.pipe(map(result => result.matches), tap(() => this.changeDetectorRef.detectChanges()));

and then 接着

this.tablet$.subscribe(isTablet => {
  this.isTablet = isTablet;
  console.log('IsTablet:' + this.isTablet);
});

As I am using Google Chromes screen sizes to test, this is working well for iPad but for iPad pro (1024 x 1366) the observable $tablet returns false . 当我使用Google Chromes屏幕尺寸进行测试时,这对于iPad效果很好,但对于iPad pro(1024 x 1366),可观察到的$tablet返回false I checked the API and the iPad pro screen dimensions are not defined in Breakpoints . 我检查了API,并且iPad Pro屏幕尺寸未在Breakpoints定义。

What is the best work around in this scenario. 在这种情况下最好的解决方法是什么。

You can pass a custom media query in to the observe function of this.breakpointObserver . 您可以到通过自定义媒体查询observe的功能this.breakpointObserver I'm really awful with media queries, but here's an example that I did using essentially your code. 我真的很讨厌媒体查询,但这是我使用您的代码所做的一个示例。 You'll have to play with the values a bit to get it how you want it, but this should get you started: 您必须花一点时间来获取所需的值,但这应该可以帮助您入门:

this.iPadProObservable = this.breakpointObserver.observe('(max-width: 1024px)')
  .pipe(
    map(result => result.matches),
    tap(() => this.changeDetectorRef.detectChanges())
  );

This seems to do what I expect when I use the iPad Pro Chrome preset. 当我使用iPad Pro Chrome预设时,这似乎可以达到我的期望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM