Skip to content

Commit

Permalink
[madman] prevent pulling the content down inconsistently when the key…
Browse files Browse the repository at this point in the history
…board shows up

Summary:
There are actually 2 problems:
1. in madman, we don't want to force-pull the textInput down when showing the keyboard (see #6649713) if the input is already fully-visible
2. the creativeEditor hardcoded the scrollOfset to 95, which is only correct for wizard navigation, but not for editing.

For (1):
modified ScrollResponder to prevent negative scrolling. Let me know if there's a better approach.

For (2):
compute the topOffset dynamically, and use it for scrolling purpose - no more hardcoding.

Example of the content getting pulled down:

{F22068821}

So the behavior becomes:
- when focusing a textInput, try to bring its bottom to meet the keyboard's top
- if the content needs to be pulled down to achieve that, scroll to 0 instead

Videos:

5s
https://www.facebook.com/pxlcld/mcNs
https://www.facebook.com/pxlcld/mcNw

6
https://www.facebook.com/pxlcld/mcNr
https://www.facebook.com/pxlcld/mcNq

Test Plan:
- try madman's creation flow (creative step) and Edit creative flow. The content shouldn't be pulled down anymore when the keyboard shows up. (This used to be more apparent in iPhone 6,6+ due to the bigger screen).
- @kristinatastic is happy
  • Loading branch information
fkgozali authored and oss sync committed Apr 12, 2015
1 parent 9cd155c commit 0ac6e70
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Libraries/Components/ScrollResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,16 @@ var ScrollResponderMixin = {
/**
* This method should be used as the callback to onFocus in a TextInputs'
* parent view. Note that any module using this mixin needs to return
* the parent view's ref in getScrollViewRef() in order to use this method
* the parent view's ref in getScrollViewRef() in order to use this method.
* @param {any} nodeHandle The TextInput node handle
* @param {number} additionalOffset The scroll view's top "contentInset".
* Default is 0.
* @param {bool} preventNegativeScrolling Whether to allow pulling the content
* down to make it meet the keyboard's top. Default is false.
*/
scrollResponderScrollNativeHandleToKeyboard: function(nodeHandle: any, additionalOffset?: number) {
scrollResponderScrollNativeHandleToKeyboard: function(nodeHandle: any, additionalOffset?: number, preventNegativeScrollOffset?: bool) {
this.additionalScrollOffset = additionalOffset || 0;
this.preventNegativeScrollOffset = !!preventNegativeScrollOffset;
RCTUIManager.measureLayout(
nodeHandle,
this.getNodeHandle(),
Expand All @@ -386,14 +392,23 @@ var ScrollResponderMixin = {
* @param {number} width Width of the text input.
* @param {number} height Height of the text input.
*/
scrollResponderInputMeasureAndScrollToKeyboard: function(left: number, top: number, width: number, height: number) {
scrollResponderInputMeasureAndScrollToKeyboard: function(left: number, top: number, width: number, height: number) {
if (this.keyboardWillOpenTo) {
var scrollOffsetY =
top - this.keyboardWillOpenTo.endCoordinates.screenY + height +
this.additionalScrollOffset;

// By default, this can scroll with negative offset, pulling the content
// down so that the target component's bottom meets the keyboard's top.
// If requested otherwise, cap the offset at 0 minimum to avoid content
// shifting down.
if (this.preventNegativeScrollOffset) {
scrollOffsetY = Math.max(0, scrollOffsetY);
}
this.scrollResponderScrollTo(0, scrollOffsetY);
}
this.additionalOffset = 0;
this.preventNegativeScrollOffset = false;
},

scrollResponderTextInputFocusError: function(e: Event) {
Expand Down

0 comments on commit 0ac6e70

Please sign in to comment.