Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c84528d9
Unverified
Commit
c84528d9
authored
May 07, 2021
by
Dan Field
Committed by
GitHub
May 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ==/hashCode for ViewConfiguration, avoid unnecessary layer creation/replacement (#81928)
parent
562b6f76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
view.dart
packages/flutter/lib/src/rendering/view.dart
+12
-0
view_test.dart
packages/flutter/test/rendering/view_test.dart
+39
-0
No files found.
packages/flutter/lib/src/rendering/view.dart
View file @
c84528d9
...
@@ -38,6 +38,18 @@ class ViewConfiguration {
...
@@ -38,6 +38,18 @@ class ViewConfiguration {
return
Matrix4
.
diagonal3Values
(
devicePixelRatio
,
devicePixelRatio
,
1.0
);
return
Matrix4
.
diagonal3Values
(
devicePixelRatio
,
devicePixelRatio
,
1.0
);
}
}
@override
bool
operator
==(
Object
other
)
{
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
return
other
is
ViewConfiguration
&&
other
.
size
==
size
&&
other
.
devicePixelRatio
==
devicePixelRatio
;
}
@override
int
get
hashCode
=>
hashValues
(
size
,
devicePixelRatio
);
@override
@override
String
toString
()
=>
'
$size
at
${debugFormatDouble(devicePixelRatio)}
x'
;
String
toString
()
=>
'
$size
at
${debugFormatDouble(devicePixelRatio)}
x'
;
}
}
...
...
packages/flutter/test/rendering/view_test.dart
View file @
c84528d9
...
@@ -2,12 +2,23 @@
...
@@ -2,12 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:ui'
as
ui
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'rendering_tester.dart'
;
import
'rendering_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
// Create non-const instances, otherwise tests pass even if the
// operator override is incorrect.
ViewConfiguration
createViewConfiguration
({
Size
size
=
const
Size
(
20
,
20
),
double
devicePixelRatio
=
2.0
,
})
{
return
ViewConfiguration
(
size:
size
,
devicePixelRatio:
devicePixelRatio
);
}
group
(
'RenderView'
,
()
{
group
(
'RenderView'
,
()
{
test
(
'accounts for device pixel ratio in paintBounds'
,
()
{
test
(
'accounts for device pixel ratio in paintBounds'
,
()
{
layout
(
RenderAspectRatio
(
aspectRatio:
1.0
));
layout
(
RenderAspectRatio
(
aspectRatio:
1.0
));
...
@@ -17,5 +28,33 @@ void main() {
...
@@ -17,5 +28,33 @@ void main() {
final
Size
physicalSize
=
logicalSize
*
devicePixelRatio
;
final
Size
physicalSize
=
logicalSize
*
devicePixelRatio
;
expect
(
renderer
.
renderView
.
paintBounds
,
Offset
.
zero
&
physicalSize
);
expect
(
renderer
.
renderView
.
paintBounds
,
Offset
.
zero
&
physicalSize
);
});
});
test
(
'does not replace the root layer unnecessarily'
,
()
{
final
ui
.
FlutterView
window
=
TestWindow
(
window:
ui
.
window
);
final
RenderView
view
=
RenderView
(
configuration:
createViewConfiguration
(),
window:
window
,
);
final
PipelineOwner
owner
=
PipelineOwner
();
view
.
attach
(
owner
);
view
.
prepareInitialFrame
();
final
ContainerLayer
firstLayer
=
view
.
debugLayer
!;
view
.
configuration
=
createViewConfiguration
();
expect
(
identical
(
view
.
debugLayer
,
firstLayer
),
true
);
view
.
configuration
=
createViewConfiguration
(
devicePixelRatio:
5.0
);
expect
(
identical
(
view
.
debugLayer
,
firstLayer
),
false
);
});
});
test
(
'ViewConfiguration == and hashCode'
,
()
{
final
ViewConfiguration
viewConfigurationA
=
createViewConfiguration
();
final
ViewConfiguration
viewConfigurationB
=
createViewConfiguration
();
final
ViewConfiguration
viewConfigurationC
=
createViewConfiguration
(
devicePixelRatio:
3.0
);
expect
(
viewConfigurationA
==
viewConfigurationB
,
true
);
expect
(
viewConfigurationA
!=
viewConfigurationC
,
true
);
expect
(
viewConfigurationA
.
hashCode
,
viewConfigurationB
.
hashCode
);
expect
(
viewConfigurationA
.
hashCode
!=
viewConfigurationC
.
hashCode
,
true
);
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment