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
a3971153
Unverified
Commit
a3971153
authored
Dec 16, 2020
by
RomanJos
Committed by
GitHub
Dec 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Proposal] Make mouseWheel zoom in % instead of pixels value (#71266)
InteractiveViewer scale gesture feel improvement.
parent
b11521ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
+40
-4
interactive_viewer.dart
packages/flutter/lib/src/widgets/interactive_viewer.dart
+7
-4
interactive_viewer_test.dart
packages/flutter/test/widgets/interactive_viewer_test.dart
+33
-0
No files found.
packages/flutter/lib/src/widgets/interactive_viewer.dart
View file @
a3971153
...
...
@@ -930,12 +930,15 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
widget
.
onInteractionEnd
?.
call
(
ScaleEndDetails
());
return
;
}
final
RenderBox
childRenderBox
=
_childKey
.
currentContext
!.
findRenderObject
()!
as
RenderBox
;
final
Size
childSize
=
childRenderBox
.
size
;
final
double
scaleChange
=
1.0
-
event
.
scrollDelta
.
dy
/
childSize
.
height
;
if
(
scaleChange
==
0.0
)
{
// Ignore left and right scroll.
if
(
event
.
scrollDelta
.
dy
==
0.0
)
{
return
;
}
// In the Flutter engine, the mousewheel scrollDelta is hardcoded to 20 per scroll, while a trackpad scroll can be any amount.
// The calculation for scaleChange here was arbitrarily chosen to feel natural for both trackpads and mousewheels on all platforms.
final
double
scaleChange
=
math
.
exp
(-
event
.
scrollDelta
.
dy
/
200
);
final
Offset
focalPointScene
=
_transformationController
!.
toScene
(
event
.
localPosition
,
);
...
...
packages/flutter/test/widgets/interactive_viewer_test.dart
View file @
a3971153
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -673,6 +675,37 @@ void main() {
expect
(
scenePoint
,
const
Offset
(
100
,
100
));
});
testWidgets
(
'Scaling amount is equal forth and back with a mouse scroll'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
InteractiveViewer
(
constrained:
false
,
maxScale:
100000
,
minScale:
0.01
,
transformationController:
transformationController
,
child:
Container
(
width:
1000.0
,
height:
1000.0
),
),
)),
),
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
InteractiveViewer
));
await
scrollAt
(
center
,
tester
,
const
Offset
(
0.0
,
-
200.0
));
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
math
.
exp
(
200
/
200
));
await
scrollAt
(
center
,
tester
,
const
Offset
(
0.0
,
-
200.0
));
await
tester
.
pumpAndSettle
();
// math.exp round the number too short compared to the one in transformationController.
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
closeTo
(
math
.
exp
(
400
/
200
),
0.000000000000001
));
await
scrollAt
(
center
,
tester
,
const
Offset
(
0.0
,
200.0
));
await
scrollAt
(
center
,
tester
,
const
Offset
(
0.0
,
200.0
));
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
1.0
);
});
testWidgets
(
'onInteraction can be used to get scene point'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
late
Offset
focalPoint
;
...
...
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