Repository navigation
[ScrollView][iOS] Fix contentInsetAdjustmentBehavior for the horizontal safe area (iPhone Duo) #59194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+849
−73
Open
[ScrollView][iOS] Fix contentInsetAdjustmentBehavior for the horizontal safe area (iPhone Duo) #59194
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ative/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollContentViewComponentView.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
|
|
||
| #import <React/RCTViewComponentView.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| /* | ||
| * UIView class for the <ScrollContentView> component, the content container of a <ScrollView>. | ||
| */ | ||
| @interface RCTScrollContentViewComponentView : RCTViewComponentView | ||
|
|
||
| /* | ||
| * The safe area the content is laid out clear of, as padding on top of the content container's own. The enclosing | ||
| * scroll view sets the pair of insets across its scrollable axis, and zero while its `contentInsetAdjustmentBehavior` | ||
| * is `never`. | ||
| */ | ||
| @property (nonatomic, assign) UIEdgeInsets safeAreaPadding; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
100 changes: 100 additions & 0 deletions
100
...tive/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollContentViewComponentView.mm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #import "RCTScrollContentViewComponentView.h" | ||
|
|
||
| #import <React/RCTI18nUtil.h> | ||
| #import <React/RCTUtils.h> | ||
| #import <react/renderer/components/scrollview/ScrollContentViewComponentDescriptor.h> | ||
| #import <react/renderer/components/scrollview/ScrollContentViewState.h> | ||
| #import "RCTConversions.h" | ||
| #import "RCTFabricComponentsPlugins.h" | ||
|
|
||
| using namespace facebook::react; | ||
|
|
||
| @implementation RCTScrollContentViewComponentView { | ||
| ScrollContentViewShadowNode::ConcreteState::Shared _state; | ||
| ScrollContentViewState _lastStateData; | ||
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame | ||
| { | ||
| if (self = [super initWithFrame:frame]) { | ||
| _props = ScrollContentViewShadowNode::defaultSharedProps(); | ||
| } | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
| - (void)setSafeAreaPadding:(UIEdgeInsets)safeAreaPadding | ||
| { | ||
| _safeAreaPadding = safeAreaPadding; | ||
| [self _updateStateIfNecessary]; | ||
| } | ||
|
|
||
| - (void)_updateStateIfNecessary | ||
| { | ||
| if (!_state) { | ||
| return; | ||
| } | ||
|
|
||
| UIEdgeInsets insets = _safeAreaPadding; | ||
| insets.left = RCTRoundPixelValue(insets.left); | ||
| insets.top = RCTRoundPixelValue(insets.top); | ||
| insets.right = RCTRoundPixelValue(insets.right); | ||
| insets.bottom = RCTRoundPixelValue(insets.bottom); | ||
|
|
||
| RCTI18nUtil *i18nUtil = [RCTI18nUtil sharedInstance]; | ||
| ScrollContentViewState newData; | ||
| newData.safeAreaPadding = RCTEdgeInsetsFromUIEdgeInsets(insets); | ||
| newData.swapLeftAndRightInRTL = i18nUtil.isRTL && i18nUtil.doLeftAndRightSwapInRTL; | ||
| if (newData == _lastStateData) { | ||
| return; | ||
| } | ||
|
|
||
| _lastStateData = newData; | ||
| _state->updateState( | ||
| [newData](const ScrollContentViewShadowNode::ConcreteState::Data &) | ||
| -> ScrollContentViewShadowNode::ConcreteState::SharedData { | ||
| return std::make_shared<const ScrollContentViewShadowNode::ConcreteState::Data>(newData); | ||
| }); | ||
| } | ||
|
|
||
| #pragma mark - RCTComponentViewProtocol | ||
|
|
||
| + (ComponentDescriptorProvider)componentDescriptorProvider | ||
| { | ||
| return concreteComponentDescriptorProvider<ScrollContentViewComponentDescriptor>(); | ||
| } | ||
|
|
||
| - (void)updateState:(const facebook::react::State::Shared &)state | ||
| oldState:(const facebook::react::State::Shared &)oldState | ||
| { | ||
| _state = std::static_pointer_cast<const ScrollContentViewShadowNode::ConcreteState>(state); | ||
| _lastStateData = _state->getData(); | ||
| } | ||
|
|
||
| - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask | ||
| { | ||
| [super finalizeUpdates:updateMask]; | ||
| [self _updateStateIfNecessary]; | ||
| } | ||
|
|
||
| - (void)prepareForRecycle | ||
| { | ||
| [super prepareForRecycle]; | ||
| _state.reset(); | ||
| _lastStateData = {}; | ||
| _safeAreaPadding = UIEdgeInsetsZero; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| Class<RCTComponentViewProtocol> RCTScrollContentViewCls(void) | ||
| { | ||
| return RCTScrollContentViewComponentView.class; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...e/ReactCommon/react/renderer/components/scrollview/ScrollContentViewComponentDescriptor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <react/cxxstableapi/PrivateGuard.h> | ||
|
|
||
| #include <react/renderer/components/scrollview/ScrollContentViewShadowNode.h> | ||
| #include <react/renderer/core/ConcreteComponentDescriptor.h> | ||
|
|
||
| namespace facebook::react { | ||
|
|
||
| /* | ||
| * Descriptor for the <ScrollContentView> component. | ||
| */ | ||
| class ScrollContentViewComponentDescriptor final : public ConcreteComponentDescriptor<ScrollContentViewShadowNode> { | ||
| public: | ||
| using ConcreteComponentDescriptor::ConcreteComponentDescriptor; | ||
|
|
||
| void adopt(ShadowNode &shadowNode) const override | ||
| { | ||
| static_cast<ScrollContentViewShadowNode &>(shadowNode).applySafeAreaPadding(); | ||
| ConcreteComponentDescriptor::adopt(shadowNode); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace facebook::react |
18 changes: 18 additions & 0 deletions
18
.../react-native/ReactCommon/react/renderer/components/scrollview/ScrollContentViewProps.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #include "ScrollContentViewProps.h" | ||
|
|
||
| namespace facebook::react { | ||
|
|
||
| ScrollContentViewProps::ScrollContentViewProps( | ||
| const PropsParserContext& context, | ||
| const ScrollContentViewProps& sourceProps, | ||
| const RawProps& rawProps) | ||
| : ViewProps(context, sourceProps, rawProps) {} | ||
|
|
||
| } // namespace facebook::react |
29 changes: 29 additions & 0 deletions
29
...es/react-native/ReactCommon/react/renderer/components/scrollview/ScrollContentViewProps.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <react/cxxstableapi/PrivateGuard.h> | ||
|
|
||
| #include <react/renderer/components/view/ViewProps.h> | ||
|
|
||
| namespace facebook::react { | ||
|
|
||
| /* | ||
| * Props for the <ScrollContentView> component, the content container of a | ||
| * <ScrollView>. It takes the props of <View>. | ||
| */ | ||
| class ScrollContentViewProps final : public ViewProps { | ||
| public: | ||
| ScrollContentViewProps() = default; | ||
| ScrollContentViewProps( | ||
| const PropsParserContext &context, | ||
| const ScrollContentViewProps &sourceProps, | ||
| const RawProps &rawProps); | ||
| }; | ||
|
|
||
| } // namespace facebook::react |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.