Hierarchy (view full)

Constructors

Properties

context: unknown

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

Example

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>

See

React Docs

refs: {
    [key: string]: ReactInstance;
}

Type declaration

Deprecated

See

Legacy React Docs

scrollWithoutAnimationTo?: ((y, x) => void)

Type declaration

    • (y, x): void
    • Parameters

      • y: number
      • x: number

      Returns void

Deprecated

Use scrollTo instead

state: Readonly<{}>

Type declaration

    contextType?: Context<any>

    If set, this.context will be set at runtime to the current value of the given Context.

    Example

    type MyContext = number
    const Ctx = React.createContext<MyContext>(0)

    class Foo extends React.Component {
    static contextType = Ctx
    context!: React.ContextType<typeof Ctx>
    render () {
    return <>My context's value: {this.context}</>;
    }
    }

    See

    https://react.dev/reference/react/Component#static-contexttype

    Methods

    • Special form of calling addListener that guarantees that a subscription must be tied to a component instance, and therefore will be cleaned up when the component is unmounted. It is impossible to create the subscription and pass it in - this method must be the one to create the subscription and therefore can guarantee it is retained in a way that will be cleaned up.

      Parameters

      • eventEmitter: any

        emitter to subscribe to.

      • eventType: string

        Type of event to listen to.

      • listener: (() => any)

        Function to invoke when event occurs.

          • (): any
          • Returns any

      • context: any

        Object to use as listener context.

      Returns void

    • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

      Parameters

      Returns void

    • Called immediately after a component is mounted. Setting state here will trigger re-rendering.

      Returns void

    • Called immediately after updating occurs. Not called for the initial render.

      The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.

      Parameters

      Returns void

    • componentWillMount is the closest thing to a standard "constructor" for React components.

      The keyboardWillShow is called before input focus.

      Returns void

    • Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

      Returns void

    • Displays the scroll indicators momentarily.

      Returns void

    • Parameters

      • Optional callback: (() => void)
          • (): void
          • Returns void

      Returns void

    • Returns any

    • Returns a reference to the underlying scroll responder, which supports operations like scrollTo. All ScrollView-like components should implement this method so that they can be composed while providing access to the underlying scroll responder's methods.

      Returns ScrollResponderMixin

    • Returns any

    • Runs before React applies the result of Component.render render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before Component.render render causes changes to it.

      Note: the presence of this method prevents any of the deprecated lifecycle events from running.

      Parameters

      Returns any

    • Returns ReactNode

    • Returns the node that represents native view that can be scrolled. Components can pass what node to use by defining a getScrollableNode function otherwise this is used.

      Returns any

    • Invoke this from an onMomentumScrollBegin event.

      Returns void

    • Invoke this from an onMomentumScrollEnd event.

      Returns void

    • Invoke this from an onResponderGrant event.

      Returns void

    • Invoke this from an onResponderReject event.

      Some other element is not yielding its role as responder. Normally, we'd just disable the UIScrollView, but a touch has already began on it, the UIScrollView will not accept being disabled after that. The easiest solution for now is to accept the limitation of disallowing this altogether. To improve this, find a way to disable the UIScrollView after a touch has already started.

      Returns any

    • Invoke this from an onResponderRelease event.

      Returns void

    • Returns void

    • Unfortunately, onScrollBeginDrag also fires when stopping the scroll animation, and there's not an easy way to distinguish a drag vs. stopping momentum.

      Invoke this from an onScrollBeginDrag event.

      Returns void

    • Invoke this from an onScrollEndDrag event.

      Returns void

    • Invoke this from an onScroll event.

      Returns boolean

    • Merely touch starting is not sufficient for a scroll view to become the responder. Being the "responder" means that the very next touch move/end event will result in an action/movement.

      Invoke this from an onStartShouldSetResponder event.

      onStartShouldSetResponder is used when the next move/end will trigger some UI movement/action, but when you want to yield priority to views nested inside of the view.

      There may be some cases where scroll views actually should return true from onStartShouldSetResponder: Any time we are detecting a standard tap that gives priority to nested views.

      • If a single tap on the scroll view triggers an action such as recentering a map style view yet wants to give priority to interaction views inside (such as dropped pins or labels), then we would return true from this method when there is a single touch.

      • Similar to the previous case, if a two finger "tap" should trigger a zoom, we would check the touches count, and if >= 2, we would return true.

      Returns boolean

    • There are times when the scroll view wants to become the responder (meaning respond to the next immediate touchStart/touchEnd), in a way that doesn't give priority to nested views (hence the capture phase):

      • Currently animating.
      • Tapping anywhere that is not the focused input, while the keyboard is up (which should dismiss the keyboard).

      Invoke this from an onStartShouldSetResponderCapture event.

      Returns boolean

    • We will allow the scroll view to give up its lock iff it acquired the lock during an animation. This is a very useful default that happens to satisfy many common user experiences.

      • Stop a scroll on the left edge, then turn that into an outer view's backswipe.
      • Stop a scroll mid-bounce at the top, continue pulling to have the outer view dismiss.
      • However, without catching the scroll view mid-bounce (while it is motionless), if you drag far enough for the scroll view to become responder (and therefore drag the scroll view a bit), any backswipe navigation of a swipe gesture higher in the view hierarchy, should be rejected.

      Returns boolean

    • Invoke this from an onTouchEnd event.

      Parameters

      Returns void

    • Invoke this from an onTouchMove event.

      Since we know that the SimpleEventPlugin occurs later in the plugin order, after ResponderEventPlugin, we can detect that we were not permitted to be the responder (presumably because a contained view became responder). The onResponderReject won't fire in that case - it only fires when a current responder rejects our request.

      Parameters

      Returns void

    • Invoke this from an onTouchStart event.

      Since we know that the SimpleEventPlugin occurs later in the plugin order, after ResponderEventPlugin, we can detect that we were not permitted to be the responder (presumably because a contained view became responder). The onResponderReject won't fire in that case - it only fires when a current responder rejects our request.

      Parameters

      Returns void

    • The calculations performed here assume the scroll view takes up the entire screen - even if has some content inset. We then measure the offsets of the keyboard, and compensate both for the scroll view's "contentInset".

      Parameters

      • left: number

        Position of input w.r.t. table view.

      • top: number

        Position of input w.r.t. table view.

      • width: number

        Width of the text input.

      • height: number

        Height of the text input.

      Returns void

    • A helper function for this class that lets us quickly determine if the view is currently animating. This is particularly useful to know when a touch has just started or ended.

      Returns boolean

    • Returns void

    • Returns void

    • Returns void

    • Warning, this may be called several times for a single keyboard opening. It's best to store the information in this method and then take any action at a later point (either in keyboardDidShow or other).

      Here's the order that events occur in:

      • focus
      • willShow {startCoordinates, endCoordinates} several times
      • didShow several times
      • blur
      • willHide {startCoordinates, endCoordinates} several times
      • didHide several times

      The ScrollResponder providesModule callbacks for each of these events. Even though any user could have easily listened to keyboard events themselves, using these props callbacks ensures that ordering of events is consistent - and not dependent on the order that the keyboard events are subscribed to. This matters when telling the scroll view to scroll to where the keyboard is headed - the scroll responder better have been notified of the keyboard destination before being instructed to scroll to where the keyboard will be. Stick to the ScrollResponder callbacks, and everything will work.

      WARNING: These callbacks will fire even if a keyboard is displayed in a different navigation pane. Filter out the events to determine if they are relevant to you. (For example, only if you receive these callbacks after you had explicitly focused a node etc).

      Returns void

    • 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.

      Parameters

      • nodeHandle: any

        The TextInput node handle

      • Optional additionalOffset: number

        The scroll view's top "contentInset". Default is 0.

      • Optional preventNegativeScrollOffset: boolean

      Returns void

    • A helper function to scroll to a specific point in the scrollview. This is currently used to help focus on child textviews, but can also be used to quickly scroll to any element we want to focus. Syntax:

      scrollResponderScrollTo(options: {x: number = 0; y: number = 0; animated: boolean = true})

      Note: The weird argument signature is due to the fact that, for historical reasons, the function also accepts separate arguments as an alternative to the options object. This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.

      Parameters

      • Optional x: number | {
            animated?: boolean;
            x?: number;
            y?: number;
        }
      • Optional y: number
      • Optional animated: boolean

      Returns void

    • Returns void

    • A helper function to zoom to a specific rect in the scrollview. The argument has the shape {x: number; y: number; width: number; height: number; animated: boolean = true}

      Parameters

      • rect: {
            animated?: boolean;
            height: number;
            width: number;
            x: number;
            y: number;
        }
        • Optional animated?: boolean
        • height: number
        • width: number
        • x: number
        • y: number
      • Optional animated: boolean

      Returns void

      Platform

      ios

    • Scrolls to a given x, y offset, either immediately or with a smooth animation. Syntax:

      scrollTo(options: {x: number = 0; y: number = 0; animated: boolean = true})

      Note: The weird argument signature is due to the fact that, for historical reasons, the function also accepts separate arguments as an alternative to the options object. This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.

      Parameters

      • Optional y: number | {
            animated?: boolean;
            x?: number;
            y?: number;
        }
      • Optional deprecatedX: number
      • Optional deprecatedAnimated: boolean

      Returns void

    • A helper function that scrolls to the end of the scrollview; If this is a vertical ScrollView, it scrolls to the bottom. If this is a horizontal ScrollView scrolls to the right.

      The options object has an animated prop, that enables the scrolling animation or not. The animated prop defaults to true

      Parameters

      • Optional options: {
            animated?: boolean;
        }
        • Optional animated?: boolean

      Returns void

    • This function sends props straight to native. They will not participate in future diff process - this means that if you do not include them in the next render, they will remain active (see Direct Manipulation).

      Parameters

      • nativeProps: object

      Returns void

    • Type Parameters

      • K extends never

      Parameters

      • state: null | {} | ((prevState, props) => null | {} | Pick<{}, K>) | Pick<{}, K>
      • Optional callback: (() => void)
          • (): void
          • Returns void

      Returns void

    • Called to determine whether the change in props and state should trigger a re-render.

      Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

      If false is returned, Component.render, componentWillUpdate and componentDidUpdate will not be called.

      Parameters

      Returns boolean