Skip to content

Commit 876a92c

Browse files
eadronSaadnajmi
andauthored
fix: adjust content inset behavior for macOS (#2806)
Fix content inset adjustments for macOS ScrollView. <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The four fields below are mandatory. --> <!-- This fork of react-native provides React Native for macOS for the community. It also contains some changes that are required for usage internal to Microsoft. We are working on reducing the diff between Facebook's public version of react-native and our microsoft/react-native-macos fork. Long term, we want this fork to only contain macOS concerns and have the other iOS and Android concerns contributed upstream. If you are making a new change then one of the following should be done: - Consider if it is possible to achieve the desired behavior without making a change to microsoft/react-native-macos. Often a change can be made in a layer above in facebook/react-native instead. - Create a corresponding PR against [facebook/react-native](https://github.com/facebook/react-native) **Note:** Ideally you would wait for Facebook feedback before submitting to Microsoft, since we want to ensure that this fork doesn't deviate from upstream. --> ## Summary: <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> ## Test Plan: <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. --> --------- Co-authored-by: Saad Najmi <sanajmi@microsoft.com>
1 parent 720ac15 commit 876a92c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ - (instancetype)initWithFrame:(CGRect)frame
4141
// because this attribute affects a position of vertical scrollbar; we don't want this
4242
// scrollbar flip because we also flip it with whole `UIScrollView` flip.
4343
self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
44-
#endif // [macOS]
44+
#else // [macOS
45+
// Similar to iOS's contentInsetAdjustmentBehavior fix
46+
// For example: When using NSWindowStyleMaskFullSizeContentView (hidden title bar) and ScrollView as root,
47+
// NSScrollView.automaticallyAdjustsContentInsets (default YES) adds contentInset.top to push content below the toolbar.
48+
// However, React Native doesn't know about this native contentInset adjustments,causing some caltulation issues
49+
self.automaticallyAdjustsContentInsets = NO;
50+
#endif // macOS]
4551

4652
__weak __typeof(self) weakSelf = self;
4753
_delegateSplitter = [[RCTGenericDelegateSplitter alloc] initWithDelegateUpdateBlock:^(id delegate) {

0 commit comments

Comments
 (0)