From 1e2440c00e65b4a70d94be5b4d41f47a940fdd94 Mon Sep 17 00:00:00 2001 From: dmitriiandriianov Date: Mon, 24 Jun 2024 22:18:35 +0700 Subject: [PATCH] Optional RenderManager --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 13 ++++++++----- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 2 ++ example/lib/main.dart | 19 +++++++++++++++++++ .../manager/render_parameters_manager.dart | 12 ++++++++++-- lib/src/render/render_metrics.dart | 11 ++++++----- pubspec.yaml | 2 +- 8 files changed, 48 insertions(+), 15 deletions(-) diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 8d4492f..7c56964 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 12.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 7fb7880..48fa7e4 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -127,7 +127,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -171,10 +171,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -185,6 +187,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -272,7 +275,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 = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -350,7 +353,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 = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -399,7 +402,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 = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c87d15a..5e31d3d 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ CADisableMinimumFrameDurationOnPhone + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index 70b6119..bc3495b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -49,6 +49,7 @@ class _MyHomePageState extends State { final String _text0Id = 'text0Id'; final String _text1Id = 'text1Id'; + final String _text2Id = 'text2Id'; final String _containerPositionedId = 'containerPositionedId'; final String _textBlockId = 'textBlockId'; @@ -57,6 +58,7 @@ class _MyHomePageState extends State { bool _isOpacity = false; String _text0 = ''; + String _text2 = 'No metrics'; @override void initState() { @@ -119,6 +121,15 @@ class _MyHomePageState extends State { text: 'Metrics:\n\n$_text0', ), ), + const SizedBox(height: 20), + RenderMetricsObject( + id: _text2Id, + onMount: _onUpdate, + onUpdate: _onUpdate, + child: _TextContainer( + text: 'Metrics without manager:\n\n$_text2', + ), + ), const SizedBox(height: 1500), ], ), @@ -160,6 +171,14 @@ class _MyHomePageState extends State { _isOpacity = isChange; }); } + + void _onUpdate(Object? id, RenderMetricsBox box) { + Future.delayed(const Duration(seconds: 1)).then((value) { + setState(() { + _text2 = box.data.toString(); + }); + }); + } } class _TextContainer extends StatelessWidget { diff --git a/lib/src/manager/render_parameters_manager.dart b/lib/src/manager/render_parameters_manager.dart index a3d045f..8dffc57 100644 --- a/lib/src/manager/render_parameters_manager.dart +++ b/lib/src/manager/render_parameters_manager.dart @@ -28,13 +28,21 @@ class RenderParametersManager extends RenderManager { /// Add an instance of [RenderObject] by [id]. @override void addRenderObject(T id, RenderObject renderObject) { - renderObjects[id] = renderObject as RenderMetricsBox; + if (renderObject is! RenderMetricsBox) { + return; + } + + renderObjects[id] = renderObject; } /// Update an instance of [RenderObject] by [id]. @override void updateRenderObject(T id, RenderObject renderObject) { - renderObjects[id] = renderObject as RenderMetricsBox; + if (renderObject is! RenderMetricsBox) { + return; + } + + renderObjects[id] = renderObject; } /// Delete an instance of [RenderObject] by [id]. diff --git a/lib/src/render/render_metrics.dart b/lib/src/render/render_metrics.dart index 5446f6e..ac13f17 100644 --- a/lib/src/render/render_metrics.dart +++ b/lib/src/render/render_metrics.dart @@ -40,7 +40,7 @@ typedef UnMountCallback = void Function(T id); class RenderMetricsObject extends SingleChildRenderObjectWidget { const RenderMetricsObject({ required this.id, - required this.manager, + this.manager, this.onMount, this.onUpdate, this.onUnMount, @@ -48,7 +48,7 @@ class RenderMetricsObject extends SingleChildRenderObjectWidget { Widget? child, }) : super(key: key, child: child); final T id; - final RenderManager manager; + final RenderManager? manager; final MountCallback? onMount; final MountCallback? onUpdate; final UnMountCallback? onUnMount; @@ -57,7 +57,7 @@ class RenderMetricsObject extends SingleChildRenderObjectWidget { RenderMetricsBox createRenderObject(BuildContext context) { final r = RenderMetricsBox(); onMount?.call(id, r); - manager.addRenderObject(id, r); + manager?.addRenderObject(id, r); return r; } @@ -68,13 +68,13 @@ class RenderMetricsObject extends SingleChildRenderObjectWidget { ) { if (renderObject is RenderMetricsBox) { onUpdate?.call(id, renderObject); - manager.updateRenderObject(id, renderObject); + manager?.updateRenderObject(id, renderObject); } } @override void didUnmountRenderObject(covariant RenderObject renderObject) { - manager.removeRenderObject(id); + manager?.removeRenderObject(id); onUnMount?.call(id); } } @@ -86,6 +86,7 @@ class RenderMetricsBox extends RenderProxyBox { RenderMetricsBox({ RenderBox? child, }) : super(child); + RenderData get data { final size = this.size; final width = size.width; diff --git a/pubspec.yaml b/pubspec.yaml index f01ee3e..4f9fb74 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dev_dependencies: surf_lint_rules: ^1.0.0 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: uses-material-design: true