react-native-macos/React/Views
Marc Rousavy 49a1460a37 Feature: ScrollView `automaticallyAdjustKeyboardInsets` (#31402)
Summary:
Retrying D30015799 (6e903b07fa) with a fix where ScrollViewNativeComponent was missing the automaticallyAdjustKeyboardInsets prop.
----- Original Summary
Currently, ScrollViews provide the prop `keyboardDismissMode` which lets you choose `"interactive"`. However when the keyboard is shown, it will be rendered above the ScrollView, potentially blocking content.

With the `automaticallyAdjustKeyboardInsets` prop the ScrollView will automatically adjust it's `contentInset`, `scrollIndicatorInsets` and `contentOffset` (scroll Y) props to push the content up so nothing gets blocked.

* The animation curve and duration of the Keyboard is exactly matched.
* The absolute position of the ScrollView is respected, so if the Keyboard only overlaps 10 pixels of the ScrollView, it will only get inset by 10 pixels.
* By respecting the absolute position on screen, this automatically makes it fully compatible with phones with notches (custom safe areas)
* By using the keyboard frame, this also works for different sized keyboards and even `<InputAccessoryView>`s
* This also supports `maintainVisibleContentPosition` and `autoscrollToTopThreshold`.
* I also fixed an issue with the `maintainVisibleContentPosition` (`autoscrollToTopThreshold`) prop(s), so they behave more reliably when `contentInset`s are applied. (This makes automatically scrolling to new items fully compatible with `automaticallyAdjustKeyboardInsets`)

## Changelog

* [iOS] [Added] - ScrollView: `automaticallyAdjustKeyboardInsets` prop: Automatically animate `contentInset`, `scrollIndicatorInsets` and `contentOffset` (scroll Y) to avoid the Keyboard. (respecting absolute position on screen and safe-areas)
* [iOS] [Fixed] - ScrollView: Respect `contentInset` when animating new items with `autoscrollToTopThreshold`, make `automaticallyAdjustKeyboardInsets` work with `autoscrollToTopThreshold` (includes vertical, vertical-inverted, horizontal and horizontal-inverted ScrollViews)

Pull Request resolved: https://github.com/facebook/react-native/pull/31402

Test Plan:
<table>
<tr>
<th>Before</th>
<th>After</th>
</tr>
<tr>
<td>

https://user-images.githubusercontent.com/15199031/115708680-9700aa80-a370-11eb-8016-e75d81a92cd7.MP4

</td>

<td>

https://user-images.githubusercontent.com/15199031/115708699-9b2cc800-a370-11eb-976f-c4010cd96d55.MP4

</td>
</table>

### "Why not just use `<KeyboardAvoidingView>`?"

<table>
<tr>
<th>Before (with <code>&lt;KeyboardAvoidingView&gt;</code>)</th>
<th>After (with <code>automaticallyAdjustKeyboardInsets</code>)</th>
</tr>
<tr>
<td>

https://user-images.githubusercontent.com/15199031/115708749-abdd3e00-a370-11eb-8e09-a27ffaef12b8.MP4

</td>

<td>

https://user-images.githubusercontent.com/15199031/115708777-b3044c00-a370-11eb-9b7a-e040ccb3ef8c.MP4

</td>
</table>

> Also notice how the `<KeyboardAvoidingView>` does not match the animation curve of the Keyboard

### Usage

```jsx
export const ChatPage = ({
  flatListProps,
  textInputProps
}: Props): React.ReactElement => (
  <>
    <FlatList
      {...flatListProps}
      keyboardDismissMode="interactive"
      automaticallyAdjustContentInsets={false}
      contentInsetAdjustmentBehavior="never"
      maintainVisibleContentPosition={{ minIndexForVisible: 0, autoscrollToTopThreshold: 100 }}
      automaticallyAdjustKeyboardInsets={true}
    />
    <InputAccessoryView backgroundColor={colors.white}>
      <ChatInput {...textInputProps} />
    </InputAccessoryView>
  </>
);
```

## Related Issues

* Fixes https://github.com/facebook/react-native/issues/31394
* Fixes https://github.com/facebook/react-native/issues/13073

Reviewed By: yungsters

Differential Revision: D32578661

Pulled By: sota000

fbshipit-source-id: 45985e2844275fe96304eccfd1901907dc4f9279
2021-12-06 13:31:13 -08:00
..
RefreshControl Daily `arc lint --take CLANGFORMAT` 2021-03-12 04:00:19 -08:00
SafeAreaView Remove iOS 11 version check (#32151) 2021-09-22 10:37:09 -07:00
ScrollView Feature: ScrollView `automaticallyAdjustKeyboardInsets` (#31402) 2021-12-06 13:31:13 -08:00
RCTActivityIndicatorView.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTActivityIndicatorView.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTActivityIndicatorViewManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTActivityIndicatorViewManager.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTAnimationType.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAutoInsetsProtocol.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTBorderDrawing.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTBorderDrawing.m Apply clang-format update fixes 2021-01-09 22:11:00 -08:00
RCTBorderStyle.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTComponent.h iOS: attach rootTag to the native component instance for easy access 2019-11-16 00:13:48 -08:00
RCTComponentData.h Pass RCTEventDispatcher to RCTComponentData [6/n] 2021-03-31 16:39:02 -07:00
RCTComponentData.m Pass RCTEventDispatcher to RCTComponentData [6/n] 2021-03-31 16:39:02 -07:00
RCTConvert+CoreLocation.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTConvert+CoreLocation.m Apply clang-format update fixes 2021-01-09 22:11:00 -08:00
RCTConvert+Transform.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTConvert+Transform.m Fix skewX/skewY/perspective/matrix on iOS (#28863) 2020-05-11 09:01:33 -07:00
RCTDatePicker.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTDatePicker.m Daily `arc lint --take CLANGFORMAT` 2020-09-29 04:14:33 -07:00
RCTDatePickerManager.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTDatePickerManager.m Fix DatePicker sizing issue 2021-04-28 13:48:28 -07:00
RCTFont.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTFont.mm RN: Fix NSInvalidArgumentException for Invalid Font Family Name 2021-09-16 23:23:33 -07:00
RCTLayout.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTLayout.m Apply clang-format update fixes 2021-01-09 22:11:00 -08:00
RCTMaskedView.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTMaskedView.m Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTMaskedViewManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTMaskedViewManager.m Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTModalHostView.h fix#29319 - ios dismiss modal (#31500) 2021-08-16 11:25:57 -07:00
RCTModalHostView.m fix#29319 - ios dismiss modal (#31500) 2021-08-16 11:25:57 -07:00
RCTModalHostViewController.h remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
RCTModalHostViewController.m remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
RCTModalHostViewManager.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTModalHostViewManager.m fix#29319 - ios dismiss modal (#31500) 2021-08-16 11:25:57 -07:00
RCTModalManager.h iOS: 2/5 Remove use of bridge from Modal by dismissing with visible prop 2021-05-02 15:42:49 -07:00
RCTModalManager.m iOS: 2/5 Remove use of bridge from Modal by dismissing with visible prop 2021-05-02 15:42:49 -07:00
RCTPointerEvents.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTProgressViewManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTProgressViewManager.m remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
RCTRootShadowView.h Add minimumSize to RCTRootView & RCTRootShadowView 2020-04-08 12:48:07 -07:00
RCTRootShadowView.m Add minimumSize to RCTRootView & RCTRootShadowView 2020-04-08 12:48:07 -07:00
RCTSegmentedControl.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSegmentedControl.m Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
RCTSegmentedControlManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSegmentedControlManager.m feat: add custom color for iOS13 segmented control (#27643) 2020-01-06 22:19:37 -08:00
RCTShadowView+Internal.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTShadowView+Internal.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTShadowView+Layout.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTShadowView+Layout.m Apply clang-format update fixes 2021-01-09 22:11:00 -08:00
RCTShadowView.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTShadowView.m Apply clang-format update fixes 2021-01-09 22:11:00 -08:00
RCTSlider.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTSlider.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTSliderManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSliderManager.m Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
RCTSwitch.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSwitch.m Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
RCTSwitchManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSwitchManager.m Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
RCTTextDecorationLineType.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTView.h replace contentInsetsForView: with RCTContentInsets() 2021-11-10 13:56:52 -08:00
RCTView.m replace contentInsetsForView: with RCTContentInsets() 2021-11-10 13:56:52 -08:00
RCTViewManager.h Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
RCTViewManager.m use new instead of alloc init 2021-10-20 22:18:38 -07:00
RCTViewUtils.h introduce RCTViewUtils 2021-11-09 20:42:13 -08:00
RCTViewUtils.m introduce RCTViewUtils 2021-11-09 20:42:13 -08:00
RCTWeakViewHolder.h Introducing RCTWeakViewHolder [4/n] 2021-03-31 16:39:02 -07:00
RCTWrapperViewController.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTWrapperViewController.m Make RCTEventDispatcher TurboModule-compatible 2020-10-14 02:40:10 -07:00
UIView+Private.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
UIView+React.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
UIView+React.m Remove iOS 11 version check (#32151) 2021-09-22 10:37:09 -07:00