-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1256 from openkraken/feat/window-innerWidth
Feat/window inner width
- Loading branch information
Showing
14 changed files
with
170 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// https://drafts.csswg.org/cssom-view | ||
describe('CSSOM View Module', () => { | ||
it('devicePixelRatio', () => { | ||
expect(window.devicePixelRatio >= 1).toEqual(true); | ||
}); | ||
|
||
it('innerWidth', () => { | ||
expect(window.innerWidth > 0).toEqual(true); | ||
}); | ||
|
||
it('innerHeight', () => { | ||
expect(window.innerHeight > 0).toEqual(true); | ||
}); | ||
|
||
// Custom added property. | ||
it('colorScheme', () => { | ||
expect(typeof window.colorScheme).toEqual('string'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
describe('Screen', () => { | ||
|
||
it('basic', () => { | ||
expect(screen !== undefined).toEqual(true); | ||
expect(window.screen).toEqual(screen); | ||
}); | ||
|
||
it('width', () => { | ||
expect(typeof screen.width).toEqual('number'); | ||
expect(screen.width > 0).toEqual(true); | ||
}); | ||
|
||
it('height', () => { | ||
expect(typeof screen.height).toEqual('number'); | ||
expect(screen.height > 0).toEqual(true); | ||
}); | ||
|
||
it('availWidth', () => { | ||
expect(typeof screen.availWidth).toEqual('number'); | ||
expect(screen.availWidth > 0).toEqual(true); | ||
}); | ||
|
||
it('availHeight', () => { | ||
expect(typeof screen.availHeight).toEqual('number'); | ||
expect(screen.availHeight > 0).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2022-present Alibaba Inc. All rights reserved. | ||
* Author: Kraken Team. | ||
*/ | ||
import 'dart:ui'; | ||
|
||
import 'package:kraken/foundation.dart'; | ||
|
||
// As its name suggests, the Screen interface represents information about the screen of the output device. | ||
// https://drafts.csswg.org/cssom-view/#the-screen-interface | ||
class Screen extends BindingObject { | ||
Screen([BindingContext? context]) : super(context); | ||
|
||
@override | ||
getBindingProperty(String key) { | ||
switch (key) { | ||
case 'availWidth': return availWidth; | ||
case 'availHeight': return availHeight; | ||
case 'width': return width; | ||
case 'height': return height; | ||
default: return super.getBindingProperty(key); | ||
} | ||
} | ||
|
||
// The availWidth attribute must return the width of the Web-exposed available screen area. | ||
// The Web-exposed available screen area is one of the following: | ||
// - The available area of the rendering surface of the output device, in CSS pixels. | ||
// - The area of the output device, in CSS pixels. | ||
// - The area of the viewport, in CSS pixels. | ||
// @NOTE: Why using physicalSize: in most cases, kraken is integrated into host native app, | ||
// so the size of kraken view is depending on how big is the flutter view, for users | ||
// they can not adjust size of kraken view. The [window.physicalSize] is the size of | ||
// native flutter view. (@zeroling) | ||
int get availWidth => window.physicalSize.width ~/ window.devicePixelRatio; | ||
|
||
// The availHeight attribute must return the height of the Web-exposed available screen area. | ||
int get availHeight => window.physicalSize.height ~/ window.devicePixelRatio; | ||
|
||
// The width attribute must return the width of the Web-exposed screen area. | ||
// The Web-exposed screen area is one of the following: | ||
// - The area of the output device, in CSS pixels. | ||
// - The area of the viewport, in CSS pixels. | ||
int get width => window.physicalSize.width ~/ window.devicePixelRatio; | ||
|
||
// The height attribute must return the height of the Web-exposed screen area. | ||
int get height => window.physicalSize.height ~/ window.devicePixelRatio; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters