From 753f578504270e898340903a8a2cc6f23272a6de Mon Sep 17 00:00:00 2001 From: JiWoong Sul Date: Fri, 5 Dec 2025 16:06:30 +0900 Subject: [PATCH] =?UTF-8?q?fix(ad):=20=EB=86=92=EC=9D=B4=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=ED=85=9C=ED=94=8C=EB=A6=BF/=EC=B5=9C?= =?UTF-8?q?=EC=86=8C=EB=86=92=EC=9D=B4=20=EC=9E=90=EB=8F=99=20=EC=A1=B0?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/native_ad_placeholder.dart | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/presentation/widgets/native_ad_placeholder.dart b/lib/presentation/widgets/native_ad_placeholder.dart index 7a02a1d..1686324 100644 --- a/lib/presentation/widgets/native_ad_placeholder.dart +++ b/lib/presentation/widgets/native_ad_placeholder.dart @@ -19,7 +19,7 @@ class NativeAdPlaceholder extends StatefulWidget { const NativeAdPlaceholder({ super.key, this.margin, - this.height = 360, + this.height = 200, this.refreshInterval = const Duration(minutes: 2), this.enabled = true, }); @@ -55,6 +55,14 @@ class _NativeAdPlaceholderState extends State { return; } + final oldType = _templateTypeForHeight(oldWidget.height); + final newType = _templateTypeForHeight(widget.height); + + if (oldType != newType) { + _loadAd(); + return; + } + if (!oldWidget.enabled && widget.enabled) { _loadAd(); return; @@ -92,10 +100,11 @@ class _NativeAdPlaceholderState extends State { }); final adUnitId = AdHelper.nativeAdUnitId; + final templateType = _templateTypeForHeight(widget.height); _nativeAd = NativeAd( adUnitId: adUnitId, request: const AdRequest(), - nativeTemplateStyle: _buildTemplateStyle(), + nativeTemplateStyle: _buildTemplateStyle(templateType), listener: NativeAdListener( onAdLoaded: (ad) { if (!mounted) { @@ -131,10 +140,10 @@ class _NativeAdPlaceholderState extends State { _refreshTimer = Timer(delay, _loadAd); } - NativeTemplateStyle _buildTemplateStyle() { + NativeTemplateStyle _buildTemplateStyle(TemplateType templateType) { final isDark = Theme.of(context).brightness == Brightness.dark; return NativeTemplateStyle( - templateType: TemplateType.medium, + templateType: templateType, mainBackgroundColor: isDark ? AppColors.darkSurface : Colors.white, cornerRadius: 0, callToActionTextStyle: NativeTemplateTextStyle( @@ -218,15 +227,25 @@ class _NativeAdPlaceholderState extends State { } double _resolveContainerHeight() { - final platformMinHeight = switch (defaultTargetPlatform) { + final templateType = _templateTypeForHeight(widget.height); + final minHeight = _templateMinHeight(templateType); + return max(widget.height, minHeight); + } + + TemplateType _templateTypeForHeight(double height) { + // Medium 템플릿은 SDK 기본 레이아웃이 커서, 높이가 낮을 경우 Small로 대체해 잘림을 방지한다. + return height < 320 ? TemplateType.small : TemplateType.medium; + } + + double _templateMinHeight(TemplateType type) { + if (type == TemplateType.small) { + return 120; + } + return switch (defaultTargetPlatform) { TargetPlatform.iOS => 402.0, TargetPlatform.android => 350.0, _ => 320.0, }; - - // 네이티브 템플릿(Medium) 기본 레이아웃이 플랫폼별로 350~402dp를 요구해 - // 호출자가 지정한 높이보다 작을 경우 클리핑을 막기 위해 최소 높이를 강제한다. - return max(widget.height, platformMinHeight); } BoxDecoration _decoration(bool isDark) {