Skip to content

Commit

Permalink
Optional RenderManager
Browse files Browse the repository at this point in the history
  • Loading branch information
knightforce-rapty committed Jun 24, 2024
1 parent 4d5a525 commit 1e2440c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
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>9.0</string>
<string>12.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -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 = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
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 = "1300"
LastUpgradeVersion = "1510"
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 @@ -45,5 +45,7 @@
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
19 changes: 19 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {

final String _text0Id = 'text0Id';
final String _text1Id = 'text1Id';
final String _text2Id = 'text2Id';
final String _containerPositionedId = 'containerPositionedId';
final String _textBlockId = 'textBlockId';

Expand All @@ -57,6 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
bool _isOpacity = false;

String _text0 = '';
String _text2 = 'No metrics';

@override
void initState() {
Expand Down Expand Up @@ -119,6 +121,15 @@ class _MyHomePageState extends State<MyHomePage> {
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),
],
),
Expand Down Expand Up @@ -160,6 +171,14 @@ class _MyHomePageState extends State<MyHomePage> {
_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 {
Expand Down
12 changes: 10 additions & 2 deletions lib/src/manager/render_parameters_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ class RenderParametersManager<T> extends RenderManager<T> {
/// 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].
Expand Down
11 changes: 6 additions & 5 deletions lib/src/render/render_metrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ typedef UnMountCallback<T> = void Function(T id);
class RenderMetricsObject<T> extends SingleChildRenderObjectWidget {
const RenderMetricsObject({
required this.id,
required this.manager,
this.manager,
this.onMount,
this.onUpdate,
this.onUnMount,
Key? key,
Widget? child,
}) : super(key: key, child: child);
final T id;
final RenderManager manager;
final RenderManager? manager;
final MountCallback<T>? onMount;
final MountCallback<T>? onUpdate;
final UnMountCallback<T>? onUnMount;
Expand All @@ -57,7 +57,7 @@ class RenderMetricsObject<T> extends SingleChildRenderObjectWidget {
RenderMetricsBox createRenderObject(BuildContext context) {
final r = RenderMetricsBox();
onMount?.call(id, r);
manager.addRenderObject(id, r);
manager?.addRenderObject(id, r);
return r;
}

Expand All @@ -68,13 +68,13 @@ class RenderMetricsObject<T> 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);
}
}
Expand All @@ -86,6 +86,7 @@ class RenderMetricsBox extends RenderProxyBox {
RenderMetricsBox({
RenderBox? child,
}) : super(child);

RenderData get data {
final size = this.size;
final width = size.width;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1e2440c

Please sign in to comment.