mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
iOS: Support inline view truncation (#21456)
Summary: If text is truncated and an inline view appears after the truncation point, the user should not see the inline view. Instead, we have a bug such that the inline view is always visible at the end of the visible text. This commit fixes this by marking the inline view as hidden if it appears after the truncation point. This appears to be a regression. React Native used to have logic similar to what this commit is adding: https://github.com/facebook/react-native/blob/1e2a924ba60001c6f0587c7561536f00b2922cbf/Libraries/Text/RCTShadowText.m#L186-L192 **Before fix** Inline view (blue square) is visible even though it appears after the truncation point:  The full text being rendered was: ``` <Text numberOfLines={1}> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} /> </Text> ``` **After fix** Inline view is properly truncated:  **Test Plan** Tested that the inline view is hidden if it appears after the truncation point when `numberOfLines` is 1 and 2. Similarly, verified that the inline view is visible if it appears before the truncation point. **Release Notes** [IOS] [BUGFIX] [Text] - Fix case where inline view is visible even though it should have been truncated Adam Comella Microsoft Corp. Pull Request resolved: https://github.com/facebook/react-native/pull/21456 Differential Revision: D10182991 Pulled By: shergin fbshipit-source-id: a5bddddb1bb8672b61d4feaa04013a92c8224155
This commit is contained in:
committed by
Lorenzo Sciandra
parent
356ac5d004
commit
ac5aaec03f
@@ -290,6 +290,9 @@
|
||||
RCTRoundPixelValue(attachmentSize.width),
|
||||
RCTRoundPixelValue(attachmentSize.height)
|
||||
}};
|
||||
|
||||
NSRange truncatedGlyphRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:range.location];
|
||||
BOOL viewIsTruncated = NSIntersectionRange(range, truncatedGlyphRange).length != 0;
|
||||
|
||||
RCTLayoutContext localLayoutContext = layoutContext;
|
||||
localLayoutContext.absolutePosition.x += frame.origin.x;
|
||||
@@ -300,9 +303,11 @@
|
||||
layoutDirection:self.layoutMetrics.layoutDirection
|
||||
layoutContext:localLayoutContext];
|
||||
|
||||
// Reinforcing a proper frame origin for the Shadow View.
|
||||
RCTLayoutMetrics localLayoutMetrics = shadowView.layoutMetrics;
|
||||
localLayoutMetrics.frame.origin = frame.origin;
|
||||
localLayoutMetrics.frame.origin = frame.origin; // Reinforcing a proper frame origin for the Shadow View.
|
||||
if (viewIsTruncated) {
|
||||
localLayoutMetrics.displayType = RCTDisplayTypeNone;
|
||||
}
|
||||
[shadowView layoutWithMetrics:localLayoutMetrics layoutContext:localLayoutContext];
|
||||
}
|
||||
];
|
||||
|
||||
@@ -490,6 +490,7 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
UIUserInterfaceLayoutDirection layoutDirection;
|
||||
BOOL isNew;
|
||||
BOOL parentIsNew;
|
||||
RCTDisplayType displayType;
|
||||
} RCTFrameData;
|
||||
|
||||
// Construct arrays then hand off to main thread
|
||||
@@ -507,6 +508,7 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
layoutMetrics.layoutDirection,
|
||||
shadowView.isNewView,
|
||||
shadowView.superview.isNewView,
|
||||
layoutMetrics.displayType
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -568,6 +570,7 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
RCTLayoutAnimation *updatingLayoutAnimation = isNew ? nil : layoutAnimationGroup.updatingLayoutAnimation;
|
||||
BOOL shouldAnimateCreation = isNew && !frameData.parentIsNew;
|
||||
RCTLayoutAnimation *creatingLayoutAnimation = shouldAnimateCreation ? layoutAnimationGroup.creatingLayoutAnimation : nil;
|
||||
BOOL isHidden = frameData.displayType == RCTDisplayTypeNone;
|
||||
|
||||
void (^completion)(BOOL) = ^(BOOL finished) {
|
||||
completionsCalled++;
|
||||
@@ -583,6 +586,10 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
if (view.reactLayoutDirection != layoutDirection) {
|
||||
view.reactLayoutDirection = layoutDirection;
|
||||
}
|
||||
|
||||
if (view.isHidden != isHidden) {
|
||||
view.hidden = isHidden;
|
||||
}
|
||||
|
||||
if (creatingLayoutAnimation) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user