Skip to content

Commit

Permalink
Merge pull request #56 from VictorOhashi/fix/popover-render
Browse files Browse the repository at this point in the history
Fix/popover render
  • Loading branch information
minikin authored Dec 18, 2022
2 parents 49dcafb + b42961f commit e51210e
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Example",
"request": "launch",
"type": "dart",
"flutterMode": "profile",
"flutterMode": "debug",
"program": "example/lib/main.dart",
}
]
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.2.8] - TBA

TODO:


## [0.2.7] - 23.10.2022

- Add `popoverTransitionBuilder`. Users can provide custom animation transition now. (thanks [@sanjidbillah](https://github.com/sanjidbillah)).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Source: [Human Interface Guidelines.

```yaml
dependencies:
popover: ^0.2.7
popover: ^0.2.8
```
## Example
Expand Down
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.20'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>11.0</string>
</dict>
</plist>
8 changes: 4 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -350,7 +350,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -399,7 +399,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.7"
version: "0.2.8"
sky_engine:
dependency: transitive
description: flutter
Expand Down
99 changes: 37 additions & 62 deletions lib/src/popover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ import 'utils/popover_utils.dart';
///
/// The `onPop` called to veto attempts by the user to dismiss the popover.
///
/// Pass `mounted` property from parent widget to the `isParentAlive`
/// function to prevent red screen of death.
/// `isParentAlive : () => mounted`
///
/// The `constraints` is popover's constraints.
///
/// The `routeSettings` is data that might be useful in constructing a [Route].
Expand Down Expand Up @@ -96,7 +92,11 @@ Future<T?> showPopover<T extends Object?>({
double? width,
double? height,
VoidCallback? onPop,
bool Function()? isParentAlive,
@Deprecated(
'This argument is ignored. Implementation of [PopoverItem] was updated.'
'This feature was deprecated in v0.2.8',
)
bool Function()? isParentAlive,
BoxConstraints? constraints,
RouteSettings? routeSettings,
String? barrierLabel,
Expand All @@ -110,8 +110,30 @@ Future<T?> showPopover<T extends Object?>({

return Navigator.of(context, rootNavigator: true).push<T>(
RawDialogRoute<T>(
pageBuilder: (_, __, ___) {
return Builder(builder: (_) => const SizedBox.shrink());
pageBuilder: (_, animation, __) {
return WillPopScope(
onWillPop: () {
onPop?.call();
return Future.value(true);
},
child: PopoverItem(
transition: transition,
child: Builder(builder: bodyBuilder),
context: context,
backgroundColor: backgroundColor,
direction: direction,
radius: radius,
boxShadow: shadow,
animation: animation,
arrowWidth: arrowWidth,
arrowHeight: arrowHeight,
constraints: constraints,
arrowDxOffset: arrowDxOffset,
arrowDyOffset: arrowDyOffset,
contentDyOffset: contentDyOffset,
key: key,
),
);
},
barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel ??=
Expand All @@ -120,62 +142,15 @@ Future<T?> showPopover<T extends Object?>({
transitionDuration: transitionDuration,
settings: routeSettings,
transitionBuilder: (builderContext, animation, _, child) {
return WillPopScope(
onWillPop: () {
if (onPop != null) {
onPop();
return Future.value(true);
} else {
return Future.value(true);
}
},
child: popoverTransitionBuilder == null
? FadeTransition(
opacity: CurvedAnimation(
parent: animation,
curve: Curves.easeOut,
),
child: PopoverItem(
transition: transition,
child: bodyBuilder(builderContext),
context: context,
backgroundColor: backgroundColor,
direction: direction,
radius: radius,
boxShadow: shadow,
animation: animation,
arrowWidth: arrowWidth,
arrowHeight: arrowHeight,
constraints: constraints,
arrowDxOffset: arrowDxOffset,
arrowDyOffset: arrowDyOffset,
contentDyOffset: contentDyOffset,
isParentAlive: isParentAlive,
key: key,
),
)
: popoverTransitionBuilder(
animation,
PopoverItem(
transition: transition,
child: bodyBuilder(builderContext),
context: context,
backgroundColor: backgroundColor,
direction: direction,
radius: radius,
boxShadow: shadow,
animation: animation,
arrowWidth: arrowWidth,
arrowHeight: arrowHeight,
constraints: constraints,
arrowDxOffset: arrowDxOffset,
arrowDyOffset: arrowDyOffset,
contentDyOffset: contentDyOffset,
isParentAlive: isParentAlive,
key: key,
),
return popoverTransitionBuilder == null
? FadeTransition(
opacity: CurvedAnimation(
parent: animation,
curve: Curves.easeOut,
),
);
child: child,
)
: popoverTransitionBuilder(animation, child);
},
),
);
Expand Down
22 changes: 11 additions & 11 deletions lib/src/popover_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ import 'popover_render_shifted_box.dart';
import 'popover_transition.dart';

class PopoverContext extends SingleChildRenderObjectWidget {
final Rect? attachRect;
final PopoverTransition transition;
final Animation<double> animation;
final Rect attachRect;
final Color? backgroundColor;
final List<BoxShadow>? boxShadow;
final Animation<double>? animation;
final double? radius;
final PopoverDirection? direction;
final double? arrowWidth;
final double? arrowHeight;
final PopoverTransition transition;
final double arrowHeight;

const PopoverContext({
required this.transition,
Widget? child,
this.attachRect,
required this.animation,
required this.attachRect,
required this.arrowHeight,
super.child,
this.backgroundColor,
this.boxShadow,
this.animation,
this.radius,
this.direction,
this.arrowWidth,
this.arrowHeight,
}) : super(child: child);
});

@override
RenderObject createRenderObject(BuildContext context) {
return PopoverRenderShiftedBox(
attachRect: attachRect,
color: backgroundColor,
boxShadow: boxShadow,
scale: animation!.value,
scale: animation.value,
direction: direction,
radius: radius,
arrowWidth: arrowWidth,
Expand All @@ -51,7 +51,7 @@ class PopoverContext extends SingleChildRenderObjectWidget {
..attachRect = attachRect
..color = backgroundColor
..boxShadow = boxShadow
..scale = transition == PopoverTransition.scale ? animation!.value : 1.0
..scale = transition == PopoverTransition.scale ? animation.value : 1.0
..direction = direction
..radius = radius
..arrowWidth = arrowWidth
Expand Down
Loading

0 comments on commit e51210e

Please sign in to comment.