Giter VIP home page Giter VIP logo

react-native-tableview's Introduction

React Native TableView

Native iOS UITableView for React Native with JSON support

npm version npm downloads code style: prettier

Contents

Features

  • Look and feel of iOS TableView - because it is! (with group/plain tableview type, sections headers, etc)
  • Display long lists of data (like country list) with no performance loss
  • Built-in accessory types (checkmark or disclosure indicator)
  • Pull to refresh!
  • Automatic scroll to initial selected value during component initialization (autoFocus property)
  • Automatic item selection with "checkmark" with old item de-selection (optionally), see demo, useful to select country/state/etc.
  • Render Native Section Index Titles (sectionIndexTitlesEnabled property)
  • Native JSON support for datasource. If you need to display large dataset, generated Javascript will became very large and impact js loading time. To solve this problem the component could read JSON directly from app bundle without JS!
  • Filter JSON datasources using NSPredicate syntax. For example you could select states for given country only (check demo)
  • Create custom UITableView cells with flexible height using React Native syntax (TableView.Cell tag)
  • Use TableView as menu to navigate to other screens (check included demo, using react-navigation https://reactnavigation.org)
  • Native editing mode for table - move/delete option is supported by using attributes canMove, canEdit for items/sections

Installation

Using npm:

npm install react-native-tableview --save

or using yarn:

yarn add react-native-tableview

⚠️ If you are on React Native < 0.60.0, you must use version 2.x.x of this library

Pods

If using CocoaPods or React Native version >= 0.60.0

cd ios && pod install && cd ..

Linking

For React Native <= 0.59 only

react-native link react-native-tableview

If fails, follow manual linking steps below,

Manual Linking

  1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
  2. Add ./node_modules/react-native-tableview/RNTableView.xcodeproj
  3. In the XCode project navigator, select your project, select the Build Phases tab and in the Link Binary With Libraries section add libRNTableView.a
  4. And in the Build Settings tab in the Search Paths/Header Search Paths section add $(SRCROOT)/../node_modules/react-native-tableview (make sure it's recursive).

Supported Styles

UITableView styles

These values are provided to the tableViewStyle prop.

<TableView tableViewStyle={TableView.Consts.Style.Grouped}>
Style Value Preview
Plain TableView.Consts.Style.Plain alt text
Grouped TableView.Consts.Style.Grouped alt text

UITableViewCell styles

These values are provided to the tableViewCellStyle prop.

<TableView tableViewCellStyle={TableView.Consts.CellStyle.Default}>
Style Value Preview
Default TableView.Consts.CellStyle.Default alt text
Value1 TableView.Consts.CellStyle.Value1 alt text
Value2 TableView.Consts.CellStyle.Value2 alt text
Subtitle TableView.Consts.CellStyle.Subtitle alt text

Accessory types

These values are provided to the accessoryType prop on the Item.

<Item accessoryType={TableView.Consts.AccessoryType.None}>
Style Value Preview
None TableView.Consts.AccessoryType.None alt text
Disclosure Indicator TableView.Consts.AccessoryType.DisclosureIndicator alt text
Disclosure Button TableView.Consts.AccessoryType.DisclosureButton alt text
Checkmark TableView.Consts.AccessoryType.Checkmark alt text
Detail Button TableView.Consts.AccessoryType.DetailButton alt text

Disclosure Indicator can also be applied by adding the arrow prop on the section.

<Section arrow>

Checkmark can also be applied by adding the selected prop on the Item.

<Item selected>

Props

For a full list of props on all components check out the typescript definitions file.

Methods

scrollTo()

Scrolls to a set of coordinates on the tableview.

/**
  * @param x Horizontal pixels to scroll
  * @param y Vertical pixels to scroll
  * @param animated With animation or not
  */
  scrollTo(x: number, y: number, animated: boolean): void;

scrollToIndex()

Scroll to an item in a section

/**
  * @param params scroll params
  * @param params.index index of the cell
  * @param params.section index of the section @default 0
  * @param params.animated scroll with animation @default true
  */
  scrollToIndex(params: { index: number, section?: number, animated?: boolean }): void;

List item format

Items in the list can be either TableView.Item or TableView.Cell. An Item is simply text. A Cell can be any complex component. However, only Items can be edited or moved. There are also issues with Cells re-rendering on data changes (#19) that can be avoided by using Items. If you want to be able to re-render, edit or move a complex component, use reactModuleForCell, described in Editable Complex Components.

Examples

Smooth scrolling with large network loaded list

demo-3

() => {
  const [loading, setLoading] = useState(true);
  const [users, setUsers] = useState([]);

  useEffect(() => {
    const getUsers = async () => {
      const response = await fetch('https://randomuser.me/api/?results=5000');
      const data = await response.json();

      setLoading(false);
      setUsers(
        data.results.map(a => ({
          name: `${a.name.first} ${a.name.last}`,
          id: a.registered,
        }))
      );
    };

    getUsers();
  }, []);

  return (
    <View style={{ flex: 1 }}>
      <Text style={styles.title}>
        {loading ? 'Fetching' : 'Fetched'} 5000 users
      </Text>

      {loading && <ActivityIndicator />}

      <TableView
        style={{ flex: 1 }}
        tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
      >
        <Section>
          {users.map(a => (
            <Item key={a.id}>{a.name}</Item>
          ))}
        </Section>
      </TableView>
    </View>
  );
};

App-bundled JSON with filter and selected value checkmarked

editing example

// list spanish provinces and add 'All states' item at the beginning

const country = 'ES';

return (
  <View style={{ flex: 1 }}>
    <Text style={styles.title}>Showing States in Spain</Text>
    <TableView
      style={{ flex: 1 }}
      json="states"
      selectedValue="ES53"
      filter={`country=='${country}'`}
      tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
      onPress={event => alert(JSON.stringify(event))}
    />
  </View>
);

Built-in editing

editing example

render() {
  return (
    <View style={{ flex: 1 }}>
      <TableView
        style={{ flex: 1 }}
        editing={navigation.getParam('editing')}
      >
        <Section canMove canEdit>
          <Item canEdit={false}>Item 1</Item>
          <Item>Item 2</Item>
          <Item>Item 3</Item>
          <Item>Item 4</Item>
          <Item>Item 5</Item>
          <Item>Item 6</Item>
          <Item>Item 7</Item>
          <Item>Item 8</Item>
        </Section>
      </TableView>
    </View>
  )
}

Pull to Refresh

pull to refresh example

function reducer(state, action) {
  switch (action.type) {
    case 'getUsers':
      return { ...state, loading: false, users: action.payload };
    case 'startRefresh':
      return { ...state, refreshing: true };
    case 'endRefresh':
      return {
        ...state,
        refreshing: false,
        amount: state.amount + 10,
        users: [...state.users, ...action.payload],
      };
    default:
      return state;
  }
}

() => {
  const [{ loading, amount, refreshing, users }, dispatch] = useReducer(
    reducer,
    {
      loading: true,
      users: [],
      refreshing: false,
      amount: 10,
    }
  );

  useEffect(() => {
    const getUsers = async () => {
      const data = await fetchUsers();
      dispatch({ type: 'getUsers', payload: data });
    };

    getUsers();
  }, []);

  const fetchUsers = async () => {
    const response = await fetch('https://randomuser.me/api/?results=10');
    const data = await response.json();

    return data.results.map(a => ({
      name: `${a.name.first} ${a.name.last}`,
      id: a.login.uuid,
    }));
  };

  const fetchMore = async () => {
    dispatch({ type: 'startRefresh' });
    const data = await fetchUsers();
    dispatch({ type: 'endRefresh', payload: data });
  };

  return (
    <View style={{ flex: 1 }}>
      <Text style={styles.title}>
        {loading ? 'Fetching' : 'Fetched'} {amount} users
      </Text>

      {loading && <ActivityIndicator />}

      <TableView
        style={{ flex: 1 }}
        tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
        canRefresh
        refreshing={refreshing}
        onRefresh={fetchMore}
      >
        <Section>
          {users.map(a => (
            <Item key={a.id}>{a.name}</Item>
          ))}
        </Section>
      </TableView>
    </View>
  );
};
}

Customization

The following style props are supported:

  • tableViewCellStyle
  • tableViewCellEditingStyle
  • separatorStyle
  • contentInset
  • contentOffset
  • scrollIndicatorInsets
  • cellLayoutMargins
  • cellSeparatorInset

Colors:

  • textColor
  • tintColor
  • selectedTextColor
  • detailTextColor
  • separatorColor
  • headerTextColor
  • headerBackgroundColor
  • footerTextColor

Base font:

  • fontSize
  • fontWeight
  • fontStyle
  • fontFamily

"Subtitle" font:

  • detailFontSize
  • detailFontWeight
  • detailFontStyle
  • detailFontFamily

Header font:

  • headerFontSize
  • headerFontWeight
  • headerFontStyle
  • headerFontFamily

Footer font:

  • footerFontSize
  • footerFontWeight
  • footerFontStyle
  • footerFontFamily

Images / Icons

An Item component takes an image and an optional imageWidth prop.

An image prop can be a string pointing to the name of an asset in your "Asset Catalog". In this case an imageWidth prop is recommended.

<Item image="icon-success.png" imageWidth={40} />

Alternatively, you can require the image from your local app code. In this case an imageWidth is unnecessary.

<Item image={require('../images/icon-success.png')} />

Editable Complex Components

Only Items can be edited or moved. However you can create a complex component that is referenced by an Item using reactModuleForCell. You will need to do several things to set this up.

  1. Write your view component.
  2. Pass the name of your view component as a prop in your <TableView> component.
  3. Create a list of <Item>s in your TableView, passing props intended for your view component.
  4. Register your view component as an App root view.

Write your cell view component.

For example,

//Should be pure... setState on top-level component doesn't seem to work

class TableViewExampleCell extends React.Component {
  render() {
    var style = { borderColor: '#aaaaaa', borderWidth: 1, borderRadius: 3 };

    // Fill the full native table cell height.
    style.flex = 1;

    // All Item props get passed to this cell inside this.props.data. Use them to control the rendering, for example background color:
    if (this.props.data.backgroundColor !== undefined) {
      style.backgroundColor = this.props.data.backgroundColor;
    }

    return (
      <View style={style}>
        <Text>
          section:{this.props.section},row:{this.props.row},label:
          {this.props.data.label}
        </Text>
        <Text> message:{this.props.data.message}</Text>
      </View>
    );
  }
}

For more examples, see examples/TableViewDemo.

Pass component as prop.

<TableView reactModuleForCell="TableViewExampleCell" >

Create list of items, passing props

<Section canEdit={true}>
  {this.props.items.map(function(item) {
    return (
      <Item
        key={'i' + item.data.date}
        label={item.label}
        message={item.message}
      />
    );
  })}
</Section>

Note that the props you pass must be primitive types: they cannot be objects. Also, note that the props become properties of the data prop in your reactModuleForCell component. That is, you pass label="foo" and in your component you pick it up as this.props.data.label.

Register your component.

Each cell you render becomes a reuseable root view or App.

var { AppRegistry } = React;

...

AppRegistry.registerComponent('TableViewExample', () => TableViewExample);

When debugging, you will see the message:

Running application "TableViewExample" with appParams: { /* params */ }. __DEV__ === true, development-level warning are ON, performance optimizations are OFF

multiple times. While slightly annoying, this does not seem to affect performance. You may also see message Unbalanced calls start/end for tag 5.

react-native-tableview's People

Contributors

aksonov avatar cancan101 avatar chetstone avatar chirag04 avatar danielbraun avatar dylancom avatar elliottsj avatar emielvanliere avatar gabrielbull avatar gpbl avatar hnryjms avatar hxiongg avatar intmainvoid avatar iroachie avatar kyler-hyuna avatar mekarina avatar mferea avatar n-kumari avatar nathan-smith avatar nyura123 avatar oblador avatar phaibin avatar q210 avatar robdel12 avatar robertying avatar sdrammis avatar sjchmiela avatar sst-nathan avatar wolfenberg avatar xlarsx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-tableview's Issues

Managing the Reordering of Rows

Thank you for putting the work into this component!

Can the component be put into "editing" mode so the cells can be reordered? Or, is this a planned feature?

Again, thank you for working on this. It will be so useful.

Separate states between sections

Currently theres not way to differentiate selections between different sections.
Am I missing something or is this the way it's suppose to currently work?

Also, I think we want to disable checkmarks if the sections arrow property is set to true.

Thoughts?

Can't use Item and Cell components side by side

Great component! Hope that you could help me, with the following use case.

Issue: Using Item and Cell components side by side results in a misbehavior of the whole tableview:

simulator screen shot 06 10 2015 22 39 28

<TableView
 style={{flex:1}}
 tableViewStyle={TableView.Consts.Style.Grouped}
 tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
 >
    <Section label="Section 1" arrow={true}>
        <Cell><Text>Heyja!</Text></Cell>
        <Item>Über</Item>
    </Section>
    <Section label="Section 2">
        <Item style={TableView.Consts.CellStyle.Subtitle} onPress={this.handleResetFavorites}>
            Option
        </Item>
    </Section>
</TableView>

Use case: I want to build the following screen, which seems to have two pitfalls:

  1. Use an ActivityIndicatorIOS inside a row
  2. View + TableView with single scrollbar. This seems not possible, since the tableview-component scrolls on it's own and the view-component stays fixed.

How could I realize this?

simulator screen shot 06 10 2015 22 44 00

Scroll to Section

Ability to scroll to section without having to check all of the items in a section.

Right now if I set selected={true} on a section, the TableView auto scrolls to that section, However this results in all items in the selection being checked.

Plan to support contentView?

Hi, nice job! Do you plan to support contentView?
My use case is to have in each cell some text left-aligned and other right-aligned.

More control over Cell?

Does Cell have more than plain text control? For example, icons, labels, even switcher, just like Settings in iOS.

img_0642

Document onChange

onChange is not in the README and there is no docs as to when it gets called.

selectionStyle on UITableViewCell

Ability to set the selectionStyle on the Cell (UITableViewCell).

for example to disable selection:

cell.selectionStyle = UITableViewCellSelectionStyle.None

Section header is now white, after update

Somehow my section headers begun to appear white, instead of grey, so there's no separation between the section header and the actual rows.
Did I do something wrong? Where is that grey defined?

Large form using tableview

Hi,

In iOS7 objectiveC I used to build large forms with NSTableView, using one cell per input field, and when the last cell/field was clicked, the tabled scrolled up so the field got above the keyboard. How can I do this with reac-native-tableview?

Thanks.

Ability to hide a Cell?

Since the number of Cells cannot change across calls to render (#19), is it possible to hide a Cell? I tried various css (height=0, display: none, etc) but I cannot seem to accomplish it.

Error on setState and re-render when using Cell

setState and re-rendering works when you use <Item></Item> but when i use <Cell> , i get the following error

Exception thrown while executing UI block: removedChildren count (0) was not what we expected (7)
2015-10-10 13:37:43.753 AppName[1670:38654] *** Assertion failure in -[RCTUIManager _childrenToRemoveFromContainer:atIndices:](), /Users/Username/Sites/AppName/node_modules/react-native/React/Modules/RCTUIManager.m:622
2015-10-10 13:37:43.761 [error][tid:main][RCTUIManager.m:887] Exception thrown while executing UI block: removedChildren count (0) was not what we expected (7)
2015-10-10 13:37:43.824 AppName[1670:38654] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 13 beyond bounds [0 .. 12]'
*** First throw call stack:
(
    0   CoreFoundation                      0x014e3a94 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00730e02 objc_exception_throw + 50
    2   CoreFoundation                      0x013afeb3 -[__NSArrayM objectAtIndex:] + 243
    3   CoreFoundation                      0x01428958 -[NSArray objectAtIndexedSubscript:] + 40
    4   AppName                  0x000505af -[RNTableView dataForRow:section:] + 159
    5   AppName                  0x0004fef2 -[RNTableView tableView:cellForRowAtIndexPath:] + 226
    6   UIKit                               0x02ea2b91 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
    7   UIKit                               0x02ea2cbf -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
    8   UIKit                               0x02e72518 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3317
    9   UIKit                               0x02e92716 __29-[UITableView layoutSubviews]_block_invoke + 52
    10  UIKit                               0x02eaca18 -[UITableView _performWithCachedTraitCollection:] + 88
    11  UIKit                               0x02e92684 -[UITableView layoutSubviews] + 214
    12  UIKit                               0x02dea16b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 813
    13  libobjc.A.dylib                     0x00745059 -[NSObject performSelector:withObject:] + 70
    14  QuartzCore                          0x02a1460c -[CALayer layoutSublayers] + 144
    15  QuartzCore                          0x02a0828e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
    16  QuartzCore                          0x02a080f2 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    17  QuartzCore                          0x029fac2b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
    18  QuartzCore                          0x02a2ec23 _ZN2CA11Transaction6commitEv + 589
    19  QuartzCore                          0x02a2f4d6 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    20  CoreFoundation                      0x013fd77e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    21  CoreFoundation                      0x013fd6de __CFRunLoopDoObservers + 398
    22  CoreFoundation                      0x013f305c __CFRunLoopRun + 1340
    23  CoreFoundation                      0x013f2866 CFRunLoopRunSpecific + 470
    24  CoreFoundation                      0x013f267b CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x05177664 GSEventRunModal + 192
    26  GraphicsServices                    0x051774a1 GSEventRun + 104
    27  UIKit                               0x02d24cc1 UIApplicationMain + 160
    28  AppName                  0x00034c4a main + 138
    29  libdyld.dylib                       0x049e9a21 start + 1
    30  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

My render function looks like this

<TableView style={{flex:1}}                       
       tableViewCellStyle={TableView.Consts.CellStyle.Default}
       onPress={this._onPress}                       
    >
    <Section 
        arrow={true}
        >
        {this.state.DocumentStore.docs.map(function(doc){
            return (
                <Cell>
                    <Text>{doc.name}</Text>
                </Cell>
            )
        })}
    </Section>

</TableView>

Mixing Cell and Item in the TableView Does not Work

I have:

                    <TableView style={{flex: 1, paddingTop: 20}}>
                        <Section label="Section 1">
                            <Cell><Text>Item 1</Text></Cell>
                        </Section>

                        <Section label="Section 2">
                            <Item>Item 2</Item>
                        </Section>
                    </TableView>

but all I see is:
image

If I remove <Cell><Text>Item 1</Text></Cell> then the "Item 2" shows up:
image

Crash when editing with Cells as children

In the TableViewDemo example, if I change the children of the Edit example from <Item> to <Cell> (like I have done here), I get a crash when I try to delete one of the items. Sometimes the first item can be deleted without a crash but the second deletion will cause the crash.
I believe this is probably related to Issues #19 and #29.

2015-11-15 14:00:02.139 [info][tid:com.facebook.React.JavaScript] 'Running application "TableViewExample" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF'
2015-11-15 14:00:10.139 TableViewDemo[72656:3397680] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 7 beyond bounds [0 .. 6]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107a21f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000106bfadeb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001079059e4 -[__NSArrayM objectAtIndex:] + 212
    3   TableViewDemo                       0x00000001065d2465 -[RNTableView dataForRow:section:] + 133
    4   TableViewDemo                       0x00000001065d1e0e -[RNTableView tableView:cellForRowAtIndexPath:] + 190
    5   UIKit                               0x00000001095d0e2a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
    6   UIKit                               0x00000001095d0f3f -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    7   UIKit                               0x00000001095a6307 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
    8   UIKit                               0x00000001095d9d1c -[UITableView _performWithCachedTraitCollection:] + 92
    9   UIKit                               0x00000001095c1884 -[UITableView layoutSubviews] + 223
    10  UIKit                               0x000000010952fe40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    11  QuartzCore                          0x00000001091fb59a -[CALayer layoutSublayers] + 146
    12  QuartzCore                          0x00000001091efe70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    13  QuartzCore                          0x00000001091efcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    14  QuartzCore                          0x00000001091e4475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    15  QuartzCore                          0x0000000109211c0a _ZN2CA11Transaction6commitEv + 486
    16  QuartzCore                          0x000000010921237c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    17  CoreFoundation                      0x000000010794d947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    18  CoreFoundation                      0x000000010794d8b7 __CFRunLoopDoObservers + 391
    19  CoreFoundation                      0x000000010794350b __CFRunLoopRun + 1147
    20  CoreFoundation                      0x0000000107942e08 CFRunLoopRunSpecific + 488
    21  GraphicsServices                    0x000000010cbfdad2 GSEventRunModal + 161
    22  UIKit                               0x000000010947b30d UIApplicationMain + 171
    23  TableViewDemo                       0x00000001064e6e7f main + 111
    24  libdyld.dylib                       0x000000010b11892d start + 1
    25  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Editing and Sorting Features

Editing, deleting, and sorting features are the main differentiation point between a TableView and ListView. These are the main things I am looking for when using a TableView.

You're off to a great start here (thank you for taking this on!), but in my view, the deleting and sorting behaviors are absolutely critical for a full, usable TableView implementation that most people are looking for - even before the performance issues are solved.

Delay rendering large data sets while using Cell

While using the Cell component of the library I noticed that there is large delay if I initialize it with a large amount of data. It takes about 3-5 seconds to render.

I am doing something like this in my component with 1000 dummy elements initialized:

  var faker = require('faker');

  var LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud modus, putant invidunt reprehendunt ne qui.';

  componentWillMount: function() {
    this.data = this.generateData();
  },

  generateData: function() {
    var data = [];
    for (var i = 0; i < 1000; i++) {
      data.push({
        image: faker.image.avatar(),
        title: ("ROW: " + i + " - " + LOREM_IPSUM)
      });
    }
    return data;
  },

  render: function() {
    let items = this.data.map((data) => (<Cell>
                        <Text>{data.title}</Text>
                    </Cell>));
    return (
            <TableView style={{flex:1}}
                       tableViewStyle={TableView.Consts.Style.Plain}
                       tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
                       onPress={(event) => console.log(event)}>
                <Section arrow={false}>
                    {items}
                </Section>
            </TableView>
        );
  },

This issue is not reproducible if I change my implementation to be Item, rather than Cell, for large data sets. Before I start digging into the source I wanted to know if this is a known limitation with Cell (slowness with initializing large data sets).

stickyHeaderIndices Equivalent for ListView

ScrollView has a property stickyHeaderIndices that allows pinning the header elements. I suggest adding the same option to ListView. Currently the results of renderHeader are not pinned.

Example of CustomCell

Hi guys. Amazing job!

Could you please add example of creating and using custom cell to readme?

No selected item initially

I'm trying to get a tableview with selectable items but none of the items are to be selected initially.

ex:

<Section label="My Items" arrow={false}>
   <Item>Item 1</Item>
    <Item>Item 2</Item>
    <Item>Item 3</Item>
 </Section>

It only seems to be working when I have at least one of the items set to selected={true}

RCT Class prefix

The FB team dislikes use of the RCT prefix (i've been pinged about that personally).

Would you entertain a PR to Rename the project and related classes to something like RNTV?

reloading data

I'm using the render2 from the examples method of drawing a table with a mix of inline static cells (for testing) and a bunch rendered into a variable and included in sections using { varWithItems }

I'm having trouble updating the cells.

Basically I'm waiting for an api call then updating the variable. What is happening is that when I scroll the cells out of the view then their contents get updated.

But the total number of cells isn't updated.

I'm guessing we need to reloadData on the table view but I'm not sure where that should go

selectedValue Should be Renamed to defaultSelectedValue

Either selectedValue should be renamed to defaultSelectedValue or it should be made into a controlled value.

Right now, selectedValue is not a controlled value. i.e. updating that prop should control the value selected in the component whereas right now it is just used as the initial value.

For a similar prop, see textinput which has both value and defaultValue.

Add Demo for TableView.Cell

TableView.Cell was advertised but it's not clear how it's intended to be used, especially from the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.