diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d3282..a428cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/tilt_stream_builder.dart b/lib/src/tilt_stream_builder.dart index b3a02ef..1ccc6ae 100644 --- a/lib/src/tilt_stream_builder.dart +++ b/lib/src/tilt_stream_builder.dart @@ -70,6 +70,8 @@ class _TiltStreamBuilderState extends State { late TiltStream latestTiltStream = TiltStream(position: position, gesturesType: GesturesType.none); + late Orientation mediaOrientation; + /// 手势协调器 async.Timer? _gesturesHarmonizerTimer; @@ -108,6 +110,12 @@ class _TiltStreamBuilderState extends State { super.dispose(); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + mediaOrientation = MediaQuery.of(context).orientation; + } + @override Widget build(BuildContext context) { return StreamBuilder( @@ -150,7 +158,22 @@ class _TiltStreamBuilderState extends State { 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; } diff --git a/pubspec.yaml b/pubspec.yaml index f456d3e..b291ca8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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