Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f998a9a
improve text line height calculation on ios
ArekChr Oct 8, 2024
8168cf0
add comments
ArekChr Oct 9, 2024
164bf0c
add safeguards to prevent out-of-bounds crash when accessing text att…
ArekChr Oct 9, 2024
f79a614
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 9, 2024
b044af9
codegen feature flags
ArekChr Oct 9, 2024
4844731
Fix namespace for ReactNativeFeatureFlags in RCTTextView
ArekChr Oct 9, 2024
76faa56
refactor: separate feature flat per platform
ArekChr Oct 11, 2024
9e5ed70
fix: add React-featureflags pod for dynamic frameworks configuration
ArekChr Oct 11, 2024
09118be
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 14, 2024
193d804
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 16, 2024
a41f8c8
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 17, 2024
2ec676c
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 21, 2024
848e4b2
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 22, 2024
045ced9
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 28, 2024
c46a96f
update feature flags
ArekChr Oct 28, 2024
d4e44de
fix: feature flag import in rn-tester dynamic frameworks
ArekChr Oct 30, 2024
b950279
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Oct 30, 2024
3610212
fix: update feature flags
ArekChr Oct 30, 2024
ffc5503
Merge remote-tracking branch 'upstream/main' into improve-lineheight-…
ArekChr Nov 18, 2024
7fd5214
Merge remote-tracking branch 'upstream/main' into improve-lineheight-…
ArekChr Dec 17, 2024
4e35916
fix: add missing expectedReleaseValue to feature flags config
ArekChr Dec 17, 2024
81e560b
refactor: remove unused flag on android
ArekChr Dec 17, 2024
a52fb88
Merge remote-tracking branch 'upstream/main' into improve-lineheight-…
ArekChr Dec 20, 2024
3a13ddf
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jan 7, 2025
42a65c1
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jan 16, 2025
44d47fe
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jan 30, 2025
9293ecd
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jan 31, 2025
f935bef
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 3, 2025
eb3e471
simplify offset calculation
ArekChr Feb 3, 2025
074e047
Handle font multiplier for dynamic type in text storage fallback
ArekChr Feb 3, 2025
ec11dc6
Exit early if minimumLineHeight is not set
ArekChr Feb 3, 2025
696c599
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 10, 2025
a763b38
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 13, 2025
0e2dbb6
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 17, 2025
59c85f1
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 25, 2025
16226ba
update feature flags
ArekChr Feb 25, 2025
672ef86
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Feb 27, 2025
17ee8c8
fix positioning when lineheight > textheight
ArekChr Mar 4, 2025
a8b5557
fix: font metrics on ios
ArekChr Mar 7, 2025
7bed2d9
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Mar 7, 2025
b911e26
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Mar 12, 2025
a822789
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Mar 25, 2025
582e1be
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Apr 1, 2025
ffaa3ae
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Apr 10, 2025
93e547c
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Apr 14, 2025
b8e9f96
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr May 8, 2025
cbb8efe
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr May 12, 2025
b361acb
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr May 27, 2025
8ec3967
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jun 5, 2025
a17189e
remove old arch impl
ArekChr Jun 9, 2025
10fe311
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jun 24, 2025
be99178
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jul 30, 2025
54bd5d7
Update RCTParagraphComponentView.mm
ArekChr Oct 6, 2025
328ea06
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Dec 12, 2025
3e94c38
fix: run featureflags gen
ArekChr Dec 12, 2025
c7407af
sync pods in rn-tester
ArekChr Dec 12, 2025
856cfaa
fix(iOS): properly modify frame for line height centering
ArekChr Dec 12, 2025
8a0de4a
fix(iOS): align line height centering rounding with Android
ArekChr Dec 12, 2025
be95918
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Jan 7, 2026
8ddb782
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr Apr 22, 2026
adc2645
Merge branch 'main' into improve-lineheight-calc-ios
ArekChr May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,35 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
return nil;
}

- (void)adjustFrameForLineHeightCentering:(NSAttributedString *)attributedText
frame:(CGRect *)frame {
if (!attributedText || attributedText.length == 0) {
return;
}

UIFont *font = [attributedText attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
Comment thread
ArekChr marked this conversation as resolved.
if (!font) {
font = [UIFontMetrics.defaultMetrics scaledFontForFont:[UIFont systemFontOfSize:14]];
}

NSParagraphStyle *paragraphStyle = [attributedText attribute:NSParagraphStyleAttributeName atIndex:0 effectiveRange:NULL];

if (!paragraphStyle || paragraphStyle.minimumLineHeight == 0) {
return;
}

CGFloat lineHeight = paragraphStyle.minimumLineHeight;
CGFloat ascent = font.ascender;
CGFloat descent = fabs(font.descender);
CGFloat textHeight = ascent + descent;

// Adjust vertical offset to ensure text is vertically centered relative to the line height.
CGFloat difference = MAX(0, textHeight - lineHeight);
CGFloat verticalOffset = difference / 2.0;

frame->origin.y += verticalOffset;
}

- (void)drawRect:(CGRect)rect
{
if (!_state) {
Expand All @@ -406,6 +435,11 @@ - (void)drawRect:(CGRect)rect

CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());

if (ReactNativeFeatureFlags::enableLineHeightCenteringOnIOS()) {
NSAttributedString *attributedText = RCTNSAttributedStringFromAttributedString(_state->getData().attributedString);
[self adjustFrameForLineHeightCentering:attributedText frame:&frame];
}

[nativeTextLayoutManager drawAttributedString:stateData.attributedString
paragraphAttributes:_paragraphAttributes
frame:frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3e8cc4e23730f3171824faaf2053bbd9>>
* @generated SignedSource<<7e0ea97c8b9eb860fbb4d2c9cd818937>>
*/

/**
Expand Down Expand Up @@ -234,6 +234,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableLayoutAnimationsOnIOS(): Boolean = accessor.enableLayoutAnimationsOnIOS()

/**
* When enabled, custom line height calculation will be centered from top to bottom.
*/
@JvmStatic
public fun enableLineHeightCenteringOnIOS(): Boolean = accessor.enableLineHeightCenteringOnIOS()

/**
* Make RCTUnsafeExecuteOnMainQueueSync less likely to deadlock, when used in conjuction with sync rendering/events.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1b877147588a851daaee1a2b4494312a>>
* @generated SignedSource<<0441143cbfa934e37b8e9bfa5f3e8fa1>>
*/

/**
Expand Down Expand Up @@ -54,6 +54,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableKeyEventsCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLineHeightCenteringOnIOSCache: Boolean? = null
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
private var enableMutationObserverByDefaultCache: Boolean? = null
Expand Down Expand Up @@ -415,6 +416,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableLineHeightCenteringOnIOS(): Boolean {
var cached = enableLineHeightCenteringOnIOSCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableLineHeightCenteringOnIOS()
enableLineHeightCenteringOnIOSCache = cached
}
return cached
}

override fun enableMainQueueCoordinatorOnIOS(): Boolean {
var cached = enableMainQueueCoordinatorOnIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a09de0b0d4b342796ff3fcc1b52fc53a>>
* @generated SignedSource<<0d71519602fd80a0f0c84eb7f2534607>>
*/

/**
Expand Down Expand Up @@ -96,6 +96,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableLayoutAnimationsOnIOS(): Boolean

@DoNotStrip @JvmStatic public external fun enableLineHeightCenteringOnIOS(): Boolean

@DoNotStrip @JvmStatic public external fun enableMainQueueCoordinatorOnIOS(): Boolean

@DoNotStrip @JvmStatic public external fun enableModuleArgumentNSNullConversionIOS(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b08dd880f47d31353cd29e4bcc63090d>>
* @generated SignedSource<<8ff3ad95d98ae88de2f040518cc436a9>>
*/

/**
Expand Down Expand Up @@ -91,6 +91,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableLayoutAnimationsOnIOS(): Boolean = true

override fun enableLineHeightCenteringOnIOS(): Boolean = false

override fun enableMainQueueCoordinatorOnIOS(): Boolean = false

override fun enableModuleArgumentNSNullConversionIOS(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c3cb6a890e22fe2ac279c3a9aa65b096>>
* @generated SignedSource<<3f94382901a0c91aa88ca3cdb20bd29a>>
*/

/**
Expand Down Expand Up @@ -58,6 +58,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableKeyEventsCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLineHeightCenteringOnIOSCache: Boolean? = null
private var enableMainQueueCoordinatorOnIOSCache: Boolean? = null
private var enableModuleArgumentNSNullConversionIOSCache: Boolean? = null
private var enableMutationObserverByDefaultCache: Boolean? = null
Expand Down Expand Up @@ -453,6 +454,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun enableLineHeightCenteringOnIOS(): Boolean {
var cached = enableLineHeightCenteringOnIOSCache
if (cached == null) {
cached = currentProvider.enableLineHeightCenteringOnIOS()
accessedFeatureFlags.add("enableLineHeightCenteringOnIOS")
enableLineHeightCenteringOnIOSCache = cached
}
return cached
}

override fun enableMainQueueCoordinatorOnIOS(): Boolean {
var cached = enableMainQueueCoordinatorOnIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1348346948cf4212dd312c48b5bfe917>>
* @generated SignedSource<<b189db0bf6871197ae8b06cd494beb24>>
*/

/**
Expand Down Expand Up @@ -91,6 +91,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableLayoutAnimationsOnIOS(): Boolean

@DoNotStrip public fun enableLineHeightCenteringOnIOS(): Boolean

@DoNotStrip public fun enableMainQueueCoordinatorOnIOS(): Boolean

@DoNotStrip public fun enableModuleArgumentNSNullConversionIOS(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ed750080bd0e891a1a11887afb7d7c01>>
* @generated SignedSource<<ce47170e5f377ef9ff3f43ddc79594c5>>
*/

/**
Expand Down Expand Up @@ -243,6 +243,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool enableLineHeightCenteringOnIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableLineHeightCenteringOnIOS");
return method(javaProvider_);
}

bool enableMainQueueCoordinatorOnIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableMainQueueCoordinatorOnIOS");
Expand Down Expand Up @@ -741,6 +747,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnIOS(
return ReactNativeFeatureFlags::enableLayoutAnimationsOnIOS();
}

bool JReactNativeFeatureFlagsCxxInterop::enableLineHeightCenteringOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableLineHeightCenteringOnIOS();
}

bool JReactNativeFeatureFlagsCxxInterop::enableMainQueueCoordinatorOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS();
Expand Down Expand Up @@ -1144,6 +1155,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableLayoutAnimationsOnIOS",
JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnIOS),
makeNativeMethod(
"enableLineHeightCenteringOnIOS",
JReactNativeFeatureFlagsCxxInterop::enableLineHeightCenteringOnIOS),
makeNativeMethod(
"enableMainQueueCoordinatorOnIOS",
JReactNativeFeatureFlagsCxxInterop::enableMainQueueCoordinatorOnIOS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<21e508305ffc719768389f668485e57f>>
* @generated SignedSource<<2748410e775b873ab1184a9d6214d9db>>
*/

/**
Expand Down Expand Up @@ -132,6 +132,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableLayoutAnimationsOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableLineHeightCenteringOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableMainQueueCoordinatorOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a65763987ba462f3c46cd84dc8d75713>>
* @generated SignedSource<<c9048371a663a2a685ca6da2078ac547>>
*/

/**
Expand Down Expand Up @@ -162,6 +162,10 @@ bool ReactNativeFeatureFlags::enableLayoutAnimationsOnIOS() {
return getAccessor().enableLayoutAnimationsOnIOS();
}

bool ReactNativeFeatureFlags::enableLineHeightCenteringOnIOS() {
return getAccessor().enableLineHeightCenteringOnIOS();
}

bool ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS() {
return getAccessor().enableMainQueueCoordinatorOnIOS();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e068e0576073bda38f2f86f80306ee93>>
* @generated SignedSource<<0056b8384a3c72512c2a332ab104423f>>
*/

/**
Expand Down Expand Up @@ -209,6 +209,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableLayoutAnimationsOnIOS();

/**
* When enabled, custom line height calculation will be centered from top to bottom.
*/
RN_EXPORT static bool enableLineHeightCenteringOnIOS();

/**
* Make RCTUnsafeExecuteOnMainQueueSync less likely to deadlock, when used in conjuction with sync rendering/events.
*/
Expand Down
Loading