From 65ac47b738d52d90b02e4cc36c2d610146ea06f1 Mon Sep 17 00:00:00 2001 From: Jovanni Lo Date: Mon, 1 Dec 2025 22:28:49 +0800 Subject: [PATCH] refactor(cpp): use yoga namespace for StyleSizeLength (#260) * refactor(cpp): use yoga namespace for StyleSizeLength - Replace yoga::StyleSizeLength with StyleSizeLength via 'using namespace yoga' - Switch from to - Aligns with patterns used by react-native-safe-area-context Ref: https://github.com/lodev09/react-native-true-sheet/discussions/218 * chore: run tidy --- .../java/com/lodev09/truesheet/TrueSheetViewManager.kt | 8 +++++++- .../com/lodev09/truesheet/core/TrueSheetGrabberView.kt | 5 +---- .../components/TrueSheetSpec/TrueSheetViewShadowNode.cpp | 8 +++++--- ios/TrueSheetView.mm | 2 +- ios/core/TrueSheetGrabberView.mm | 3 +-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt index 15bee24..1363256 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt @@ -122,7 +122,13 @@ class TrueSheetViewManager : width = if (options.hasKey("width")) options.getDouble("width").toFloat() else null, height = if (options.hasKey("height")) options.getDouble("height").toFloat() else null, topMargin = if (options.hasKey("topMargin")) options.getDouble("topMargin").toFloat() else null, - cornerRadius = if (options.hasKey("cornerRadius") && options.getDouble("cornerRadius") >= 0) options.getDouble("cornerRadius").toFloat() else null, + cornerRadius = if (options.hasKey("cornerRadius") && + options.getDouble("cornerRadius") >= 0 + ) { + options.getDouble("cornerRadius").toFloat() + } else { + null + }, color = if (options.hasKey("color") && options.getInt("color") != 0) options.getInt("color") else null ) view.setGrabberOptions(grabberOptions) diff --git a/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt b/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt index 79c5944..da117c3 100644 --- a/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt +++ b/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt @@ -25,10 +25,7 @@ data class GrabberOptions( * Displays a small pill-shaped indicator at the top of the sheet. */ @SuppressLint("ViewConstructor") -class TrueSheetGrabberView( - context: Context, - private val options: GrabberOptions? = null -) : View(context) { +class TrueSheetGrabberView(context: Context, private val options: GrabberOptions? = null) : View(context) { companion object { private const val DEFAULT_WIDTH = 32f // dp diff --git a/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp b/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp index 4689200..eeda244 100644 --- a/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp +++ b/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp @@ -1,9 +1,11 @@ #include "TrueSheetViewShadowNode.h" -#include +#include namespace facebook::react { +using namespace yoga; + extern const char TrueSheetViewComponentName[] = "TrueSheetView"; void TrueSheetViewShadowNode::adjustLayoutWithState() { @@ -22,7 +24,7 @@ void TrueSheetViewShadowNode::adjustLayoutWithState() { // Set width if provided if (stateData.containerWidth > 0) { - adjustedStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(stateData.containerWidth)); + adjustedStyle.setDimension(yoga::Dimension::Width, StyleSizeLength::points(stateData.containerWidth)); if (adjustedStyle.dimension(yoga::Dimension::Width) != currentStyle.dimension(yoga::Dimension::Width)) { needsUpdate = true; } @@ -30,7 +32,7 @@ void TrueSheetViewShadowNode::adjustLayoutWithState() { // Set height if provided if (stateData.containerHeight > 0) { - adjustedStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(stateData.containerHeight)); + adjustedStyle.setDimension(yoga::Dimension::Height, StyleSizeLength::points(stateData.containerHeight)); if (adjustedStyle.dimension(yoga::Dimension::Height) != currentStyle.dimension(yoga::Dimension::Height)) { needsUpdate = true; } diff --git a/ios/TrueSheetView.mm b/ios/TrueSheetView.mm index 54e530a..40cb2db 100644 --- a/ios/TrueSheetView.mm +++ b/ios/TrueSheetView.mm @@ -139,7 +139,7 @@ using namespace facebook::react; // Grabber options - check if any non-default values are set const auto &grabberOpts = newProps.grabberOptions; BOOL hasGrabberOptions = grabberOpts.width > 0 || grabberOpts.height > 0 || grabberOpts.topMargin > 0 || - grabberOpts.cornerRadius >= 0 || grabberOpts.color != 0; + grabberOpts.cornerRadius >= 0 || grabberOpts.color != 0; if (hasGrabberOptions) { NSMutableDictionary *options = [NSMutableDictionary dictionary]; diff --git a/ios/core/TrueSheetGrabberView.mm b/ios/core/TrueSheetGrabberView.mm index 2b9c904..5d3b2e6 100644 --- a/ios/core/TrueSheetGrabberView.mm +++ b/ios/core/TrueSheetGrabberView.mm @@ -52,8 +52,7 @@ static const CGFloat kDefaultGrabberTopMargin = 5.0; // Create blur effect for vibrancy base UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial]; - UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect - style:UIVibrancyEffectStyleFill]; + UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect style:UIVibrancyEffectStyleFill]; // Create the vibrancy view that fills this view _vibrancyView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];