master da307fdc6805 cached
5 files
8.3 KB
2.2k tokens
1 symbols
1 requests
Download .txt
Repository: exponentjs/react-native-invertible-scroll-view
Branch: master
Commit: da307fdc6805
Files: 5
Total size: 8.3 KB

Directory structure:
gitextract_h4v_47hl/

├── .gitignore
├── InvertibleScrollView.js
├── LICENSE
├── README.md
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules


================================================
FILE: InvertibleScrollView.js
================================================
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types';
import React from 'react';
import cloneReferencedElement from 'react-clone-referenced-element';
import {
  ScrollView,
  StyleSheet,
  View,
} from 'react-native';
import ScrollableMixin from 'react-native-scrollable-mixin';

type DefaultProps = {
  renderScrollComponent: (props: Object) => ReactElement;
};

let InvertibleScrollView = createReactClass({
  mixins: [ScrollableMixin],

  propTypes: {
    ...ScrollView.propTypes,
    inverted: PropTypes.bool,
    renderScrollComponent: PropTypes.func.isRequired,
  },

  getDefaultProps(): DefaultProps {
    return {
      renderScrollComponent: props => <ScrollView {...props} />,
    };
  },

  getScrollResponder(): ReactComponent {
    return this._scrollComponent.getScrollResponder();
  },

  setNativeProps(props: Object) {
    this._scrollComponent.setNativeProps(props);
  },

  render() {
    var {
      inverted,
      renderScrollComponent,
      ...props
    } = this.props;

    if (inverted) {
      if (this.props.horizontal) {
        props.style = [styles.horizontallyInverted, props.style];
        props.children = this._renderInvertedChildren(props.children, styles.horizontallyInverted);
      } else {
        props.style = [styles.verticallyInverted, props.style];
        props.children = this._renderInvertedChildren(props.children, styles.verticallyInverted);
      }
    }

    return cloneReferencedElement(renderScrollComponent(props), {
      ref: component => { this._scrollComponent = component; },
    });
  },

  _renderInvertedChildren(children, inversionStyle) {
    return React.Children.map(children, child => {
      return child ? <View style={inversionStyle}>{child}</View> : child;
    });
  },
});

let styles = StyleSheet.create({
  verticallyInverted: {
    flex: 1,
    transform: [
      { scaleY: -1 },
    ],
  },
  horizontallyInverted: {
    flex: 1,
    transform: [
      { scaleX: -1 },
    ],
  },
});

export default InvertibleScrollView;


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015-present 650 Industries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# InvertibleScrollView [![Slack](http://slack.exponentjs.com/badge.svg)](http://slack.exponentjs.com)

InvertibleScrollView is a React Native scroll view that can be inverted so that content is rendered starting from the bottom, and the user must scroll down to reveal more. This is a common design in chat applications and the command-line terminals. InvertibleScrollView also supports horizontal scroll views to present content from right to left.

It conforms to [ScrollableMixin](https://github.com/exponentjs/react-native-scrollable-mixin) so you can compose it with other scrollable components.

[![npm package](https://nodei.co/npm/react-native-invertible-scroll-view.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/react-native-invertible-scroll-view/)

## Installation
Use this with react-native 0.8.0-rc or later.

```
npm install react-native-invertible-scroll-view
```

## Usage

Compose InvertibleScrollView with the scrollable component you would like to invert. In the case of a ListView, you would write:

```js
import React from 'react-native';
let {
  ListView,
  Text,
  TouchableHighlight,
  View,
  StyleSheet,
} = React;
import InvertibleScrollView from 'react-native-invertible-scroll-view';

class InvertedScrollComponent extends React.Component {
  constructor(props, context) {
    super(props, context);
    this._data = [];
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (r1, r2) => r1 !== r2,
      }),
    };
  }

  render() {
    return (
      <ListView
        renderScrollComponent={props => <InvertibleScrollView {...props} inverted />}
        dataSource={this.state.dataSource}
        renderHeader={this._renderHeader.bind(this)}
        renderRow={this._renderRow.bind(this)}
        style={styles.container}
      />
    );
  }

  _renderHeader() {
    return (
      <TouchableHighlight
        onPress={this._onPress.bind(this)}
        style={styles.button}>
        <Text>Add a row</Text>
      </TouchableHighlight>
    );
  }

  _renderRow(row) {
    return <Text key={row} style={styles.row}>{row}</Text>
  }

  _onPress() {
    this._data.push(`${new Date}`);
    var rows = this._data;
    // It's important to keep row IDs consistent to avoid extra rendering. You
    // may need to reverse the list of row IDs so the so that the inversion
    // will order the rows correctly.
    var rowIds = rows.map((row, index) => index).reverse();
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(rows, rowIds),
    });
  }
}

let styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  button: {
    padding: 20,
    borderStyle: 'solid',
    borderWidth: 1,
    borderColor: 'black',
  },
  row: {
    padding: 4,
  },
});
```

**NOTE:** When inverting a ListView, you must create a ListView that delegates to an InvertibleScrollView as shown above and not the other way around. Otherwise it will not be able to invert the rows and the content will look upside down. This is true for any scroll view that adds its own children, not just ListView.

## Tips and Caveats

- Horizontal scroll views are supported
- To scroll to the bottom, call `scrollTo(0)` on a ref to the scroll view
- When the scroll view is inverted, InvertibleScrollView wraps each child in a View that is flipped
- Scroll views that add children (ex: ListViews) must delegate to InvertibleScrollViews so that the children can be properly inverted
- List section headers are unsupported
- Styles like `padding` are not corrected, so top padding will actually pad the bottom of the component
- Properties like `contentOffset` and `contentInset` are not flipped; for example, the top inset adjusts the bottom of an inverted scroll view

## Implementation

InvertibleScrollView uses a scale transformation to efficiently invert the view. The scroll view's viewport is inverted to flip the entire component, and then each child is inverted again so that the content appears unflipped.


================================================
FILE: package.json
================================================
{
  "name": "react-native-invertible-scroll-view",
  "version": "2.0.0",
  "description": "An invertible ScrollView for React Native",
  "main": "InvertibleScrollView.js",
  "scripts": {},
  "repository": {
    "type": "git",
    "url": "https://github.com/exponentjs/react-native-invertible-scroll-view.git"
  },
  "keywords": [
    "react-native",
    "invertible",
    "scroll-view"
  ],
  "author": "Expo <support@expo.io>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/exponentjs/react-native-invertible-scroll-view/issues"
  },
  "homepage": "https://github.com/exponentjs/react-native-invertible-scroll-view",
  "dependencies": {
    "create-react-class": "^15.6.3",
    "prop-types": "^15.7.2",
    "react-clone-referenced-element": "^1.1.0",
    "react-native-scrollable-mixin": "^1.0.1"
  }
}
Download .txt
gitextract_h4v_47hl/

├── .gitignore
├── InvertibleScrollView.js
├── LICENSE
├── README.md
└── package.json
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: InvertibleScrollView.js
  method if (line 47) | if (this.props.horizontal) {
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
  {
    "path": ".gitignore",
    "chars": 526,
    "preview": "# Logs\nlogs\n*.log\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nl"
  },
  {
    "path": "InvertibleScrollView.js",
    "chars": 2036,
    "preview": "import createReactClass from 'create-react-class';\nimport PropTypes from 'prop-types';\nimport React from 'react';\nimport"
  },
  {
    "path": "LICENSE",
    "chars": 1089,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015-present 650 Industries\n\nPermission is hereby granted, free of charge, to any p"
  },
  {
    "path": "README.md",
    "chars": 4075,
    "preview": "# InvertibleScrollView [![Slack](http://slack.exponentjs.com/badge.svg)](http://slack.exponentjs.com)\n\nInvertibleScrollV"
  },
  {
    "path": "package.json",
    "chars": 821,
    "preview": "{\n  \"name\": \"react-native-invertible-scroll-view\",\n  \"version\": \"2.0.0\",\n  \"description\": \"An invertible ScrollView for "
  }
]

About this extraction

This page contains the full source code of the exponentjs/react-native-invertible-scroll-view GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (8.3 KB), approximately 2.2k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!