Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
feat: Updated tweets list with new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Oct 10, 2023
1 parent ea1c80e commit f16b546
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
6 changes: 6 additions & 0 deletions lib/features/wallet/presentation/wallet_page_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,10 @@ class WalletPresenter extends CompletePresenter<WalletState> {
_tokenContractUseCase.getTokensBalance(
tokenList, state.walletAddress!, shouldGetPrice);
}

void checkMaxTweetHeight(double height) {
if (height >= state.maxTweetViewHeight - 120) {
notify(() => state.maxTweetViewHeight = height + 120);
}
}
}
5 changes: 4 additions & 1 deletion lib/features/wallet/presentation/wallet_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class WalletState with EquatableMixin {

Network? network;

double maxTweetViewHeight = 620;

@override
List<Object?> get props => [
currentIndex,
Expand All @@ -48,6 +50,7 @@ class WalletState with EquatableMixin {
balanceSpots,
embeddedTweets,
xsdConversionRate,
network
network,
maxTweetViewHeight
];
}
34 changes: 8 additions & 26 deletions lib/features/wallet/presentation/widgets/tweets_list.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mxc_ui/mxc_ui.dart';
import 'package:social_embed_webview/platforms/twitter.dart';
import 'package:social_embed_webview/social_embed_webview.dart';

import '../wallet_page_presenter.dart';
import 'tweet_widget.dart';

class TweetsList extends HookConsumerWidget {
const TweetsList({super.key});
Expand All @@ -20,29 +20,11 @@ class TweetsList extends HookConsumerWidget {
children: [
...state.embeddedTweets.map(
(e) {
if (Theme.of(context).brightness == Brightness.dark) {
RegExp regex = RegExp(r'<.*?>');
final match = regex.firstMatch(e)!.group(0);
int index = match!.length - 1;
String newString =
'${match.substring(0, index)} data-theme="dark" data-width="400"${match.substring(index)}';
e = e.replaceFirst(regex, newString);
}
return Container(
margin: EdgeInsetsDirectional.only(
start: MediaQuery.of(context).size.width > 600 ? 16 : 8),
width: 320,
height: 620,
child: Theme(
data: MxcTheme.of(context).toThemeData().copyWith(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
child: SocialEmbed(
socialMediaObj: TwitterEmbedData(
embedHtml: e,
),
),
),
return Tweet(
tweetId: e,
isDark: (Theme.of(context).brightness == Brightness.dark),
height: state.maxTweetViewHeight,
checkMaxHeight: presenter.checkMaxTweetHeight,
);
},
)
Expand Down

0 comments on commit f16b546

Please sign in to comment.