Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #189 from OpenbookOrg/bugfix/remove-post-height-again
Browse files Browse the repository at this point in the history
🔥 remove post height calculation
  • Loading branch information
lifenautjoe authored Mar 28, 2019
2 parents ae60161 + e8198c9 commit 27f1a33
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 81 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PODS:

DEPENDENCIES:
- device_info (from `.symlinks/plugins/device_info/ios`)
- Flutter (from `.symlinks/flutter/ios`)
- Flutter (from `.symlinks/flutter/ios-release`)
- flutter_exif_rotation (from `.symlinks/plugins/flutter_exif_rotation/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- image_cropper (from `.symlinks/plugins/image_cropper/ios`)
Expand All @@ -62,7 +62,7 @@ EXTERNAL SOURCES:
device_info:
:path: ".symlinks/plugins/device_info/ios"
Flutter:
:path: ".symlinks/flutter/ios"
:path: ".symlinks/flutter/ios-release"
flutter_exif_rotation:
:path: ".symlinks/plugins/flutter_exif_rotation/ios"
flutter_secure_storage:
Expand Down
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand Down
100 changes: 22 additions & 78 deletions lib/widgets/post/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,91 +12,35 @@ import 'package:flutter/material.dart';
class OBPost extends StatelessWidget {
final Post post;
final OnPostDeleted onPostDeleted;
static const HEIGHT_POST_HEADER = 72.0;
static const HEIGHT_POST_REACTIONS = 35.0;
static const HEIGHT_POST_CIRCLES = 26.0;
static const HEIGHT_POST_ACTIONS = 46.0;
static const HEIGHT_POST_COMMENTS = 34.0;
static const HEIGHT_POST_DIVIDER = 5.5;
static const HEIGHT_SIZED_BOX = 16.0;
static const TOTAL_PADDING_POST_TEXT = 40.0;
static const SCHRODINGERS_HEIGHT = 2.0; // @todo: find out where its coming from
static const TOTAL_FIXED_HEIGHT = HEIGHT_POST_HEADER
+ HEIGHT_POST_REACTIONS + HEIGHT_POST_ACTIONS + HEIGHT_SIZED_BOX + HEIGHT_POST_DIVIDER + SCHRODINGERS_HEIGHT;

const OBPost(this.post, {Key key, @required this.onPostDeleted})
: super(key: key);

@override
Widget build(BuildContext context) {

return SizedBox(
height: _getTotalPostHeight(context),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
OBPostHeader(
post: post,
onPostDeleted: onPostDeleted,
),
OBPostBody(post),
OBPostReactions(post),
OBPostCircles(post),
OBPostComments(
post,
),
OBPostActions(
post,
),
const SizedBox(
height: 16,
),
OBPostDivider(),
],
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
OBPostHeader(
post: post,
onPostDeleted: onPostDeleted,
),
OBPostBody(post),
OBPostReactions(post),
OBPostCircles(post),
OBPostComments(
post,
),
OBPostActions(
post,
),
const SizedBox(
height: 16,
),
OBPostDivider(),
],
);
}

double _getTotalPostHeight(BuildContext context) {
double aspectRatio;
double finalMediaScreenHeight = 0.0;
double finalTextHeight = 0.0;
double totalHeightPost = 0.0;
double screenWidth = MediaQuery.of(context).size.width;
if (post.hasImage()) {
aspectRatio = post.getImageWidth() / post.getImageHeight();
finalMediaScreenHeight = screenWidth/aspectRatio;
}
if (post.hasVideo()) {
aspectRatio = post.getVideoWidth() / post.getVideoHeight();
finalMediaScreenHeight = screenWidth/aspectRatio;
}

if (post.hasText()) {
TextStyle style = TextStyle(fontSize: 16.0);
TextSpan text =
new TextSpan(text: post.text, style: style);

TextPainter textPainter = new TextPainter(
text: text,
textDirection: TextDirection.ltr,
textAlign: TextAlign.left,
);
textPainter.layout(maxWidth: screenWidth - 40.0); //padding is 20 in OBPostBodyText
finalTextHeight = textPainter.size.height + TOTAL_PADDING_POST_TEXT;
}

if (post.hasCircles() || (post.isEncircled != null && post.isEncircled)) {
totalHeightPost = totalHeightPost + HEIGHT_POST_CIRCLES;
}

if (post.hasCommentsCount()) {
totalHeightPost = totalHeightPost + HEIGHT_POST_COMMENTS;
}

totalHeightPost = totalHeightPost + finalMediaScreenHeight + finalTextHeight + TOTAL_FIXED_HEIGHT;

return totalHeightPost;
}
}

0 comments on commit 27f1a33

Please sign in to comment.