Skip to content

Commit

Permalink
Bug Fix: device landscape mode not match sensor orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed Sep 19, 2023
1 parent 104f321 commit 7af516c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.

## 2.0.3

### Fixes

- Fix device landscape mode not match sensor orientation.

## 2.0.2

### Improvements
Expand Down
25 changes: 24 additions & 1 deletion lib/src/tilt_stream_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class _TiltStreamBuilderState extends State<TiltStreamBuilder> {
late TiltStream latestTiltStream =
TiltStream(position: position, gesturesType: GesturesType.none);

late Orientation mediaOrientation;

/// 手势协调器
async.Timer? _gesturesHarmonizerTimer;

Expand Down Expand Up @@ -108,6 +110,12 @@ class _TiltStreamBuilderState extends State<TiltStreamBuilder> {
super.dispose();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
mediaOrientation = MediaQuery.of(context).orientation;
}

@override
Widget build(BuildContext context) {
return StreamBuilder<TiltStream>(
Expand Down Expand Up @@ -150,7 +158,22 @@ class _TiltStreamBuilderState extends State<TiltStreamBuilder> {
if (canSensorsPlatformSupport &&
enableSensors &&
_gesturesHarmonizerTimer == null) {
return latestTiltStream = tiltStream;
final sensorsX = tiltStream.position.dx;
final sensorsY = tiltStream.position.dy;
switch (mediaOrientation) {
case Orientation.portrait:
latestTiltStream = TiltStream(
position: Offset(sensorsX, sensorsY),
gesturesType: tiltStream.gesturesType,
);
break;
case Orientation.landscape:
latestTiltStream = TiltStream(
position: Offset(sensorsY, -sensorsX),
gesturesType: tiltStream.gesturesType,
);
break;
}
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Easily apply tilt parallax hover effects for Flutter, which support
# https://semver.org/spec/v2.0.0-rc.1.html
# https://dart.dev/tools/pub/versioning#semantic-versions
# https://dart.dev/tools/pub/dependencies#version-constraints
version: 2.0.2
version: 2.0.3
homepage: https://amoshuke.github.io/flutter_tilt_book
repository: https://github.com/AmosHuKe/flutter_tilt
issue_tracker: https://github.com/AmosHuKe/flutter_tilt/issues
Expand Down

0 comments on commit 7af516c

Please sign in to comment.