Skip to content

Commit 8f18477

Browse files
authored
2.2.0 #167 from aksonov/next
2 parents 312a6e9 + 0c9b2ef commit 8f18477

File tree

13 files changed

+221
-37
lines changed

13 files changed

+221
-37
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ section.
126126
<Section arrow>
127127
```
128128

129-
Checkamrk can also be applied by adding the `selected` prop on the Item.
129+
Checkmark can also be applied by adding the `selected` prop on the Item.
130130

131131
```jsx
132132
<Item selected>
@@ -137,6 +137,36 @@ Checkamrk can also be applied by adding the `selected` prop on the Item.
137137
For a full list of props on all components check out
138138
[the typescript definitions file](./src/index.d.ts).
139139

140+
141+
### Methods
142+
143+
#### `scrollTo()`
144+
145+
Scrolls to a set of coordinates on the tableview.
146+
147+
```ts
148+
/**
149+
* @param x Horizontal pixels to scroll
150+
* @param y Vertical pixels to scroll
151+
* @param animated With animation or not
152+
*/
153+
scrollTo(x: number, y: number, animated: boolean): void;
154+
```
155+
156+
#### `scrollToIndex()`
157+
158+
Scroll to an item in a section
159+
160+
```ts
161+
/**
162+
* @param params scroll params
163+
* @param params.index index of the cell
164+
* @param params.section index of the section @default 0
165+
* @param params.animated scroll with animation @default true
166+
*/
167+
scrollToIndex(params: { index: number, section?: number, animated?: boolean }): void;
168+
```
169+
140170
### List item format
141171

142172
Items in the list can be either `TableView.Item` or `TableView.Cell`. An `Item`
@@ -366,7 +396,7 @@ Catalog". In this case an `imageWidth` prop is recommended.
366396
;<Item image="icon-success.png" imageWidth={40} />
367397
```
368398

369-
Alernatively, you can `require` the image from your local app code. In this case
399+
Alternatively, you can `require` the image from your local app code. In this case
370400
an `imageWidth` is unnecessary.
371401

372402
```jsx

RNTableView.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Pod::Spec.new do |s|
22

33
s.name = "RNTableView"
4-
s.version = "2.1.1"
4+
s.version = "2.2.0"
55
s.authors = "Pavel Aksonov"
66
s.summary = "Native iOS UITableView for React Native with JSON support and more"
77
s.license = "BSD 2-Clause"
88
s.homepage = "https://github.com/aksonov/react-native-tableview"
99
s.platform = :ios, "7.0"
1010
s.source = { :git => "https://github.com/aksonov/react-native-tableview.git",
11-
:tag => "2.1.1" }
11+
:tag => "2.2.0" }
1212
s.source_files = 'RNTableView/*.{h,m}'
1313
s.preserve_paths = "**/*.js"
1414
s.dependency 'React'

RNTableView/RNTableView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@
8787
- (void)stopRefreshing;
8888
- (void)startRefreshing;
8989
- (void)scrollToOffsetX:(CGFloat)x offsetY:(CGFloat)y animated:(BOOL)animated;
90+
- (void)scrollToIndex:(NSInteger)index section:(NSInteger)section animated:(BOOL)animated;
9091

9192
@end

RNTableView/RNTableView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ -(void)stopRefreshing {
256256
[self.tableView.refreshControl endRefreshing];
257257
}
258258

259+
-(void)scrollToIndex: (NSInteger)index section:(NSInteger)section animated:(BOOL)animated {
260+
if ([self.tableView numberOfRowsInSection:section] > index) {
261+
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:index inSection:section];
262+
[self.tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionTop animated:animated];
263+
}
264+
}
265+
259266

260267
-(void)setHeaderHeight:(float)headerHeight {
261268
_headerHeight = headerHeight;

RNTableView/RNTableViewManager.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,20 @@ - (NSDictionary *)constantsToExport {
288288
}];
289289
}
290290

291+
RCT_EXPORT_METHOD(scrollToIndex:(nonnull NSNumber *)reactTag
292+
index:(NSInteger)index
293+
section:(NSInteger)section
294+
animated:(BOOL)animated)
295+
{
296+
[self.bridge.uiManager addUIBlock:
297+
^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){
298+
RNTableView *tableView = viewRegistry[reactTag];
299+
300+
if ([tableView isKindOfClass:[RNTableView class]]) {
301+
[tableView scrollToIndex:index section:section animated:animated];
302+
} else {
303+
RCTLogError(@"Cannot scrollToIndex: %@ (tag #%@) is not RNTableView", tableView, reactTag);
304+
}
305+
}];
306+
}
291307
@end

example/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start",
77
"test": "jest",
8-
"postinstall":
9-
"rm -rf node_modules/react-native-tableview/node_modules node_modules/react-native-tableview/example"
8+
"postinstall": "rm -rf node_modules/react-native-tableview/node_modules node_modules/react-native-tableview/example"
109
},
1110
"dependencies": {
1211
"prop-types": "^15.6.0",
1312
"react": "16.0.0",
1413
"react-native": "0.50.4",
1514
"react-native-tableview": "file:..",
16-
"react-navigation": "^1.0.0-beta.21"
15+
"react-navigation": "^2.0.4"
1716
},
1817
"devDependencies": {
1918
"babel-jest": "21.2.0",

example/src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppRegistry } from 'react-native'
2-
import { StackNavigator } from 'react-navigation'
2+
import { createStackNavigator } from 'react-navigation';
33
import Home from './screens/Home'
44
import Example1 from './screens/Example1'
55
import Example2 from './screens/Example2'
@@ -8,10 +8,11 @@ import Example4 from './screens/Example4'
88
import Example5 from './screens/Example5'
99
import Example6 from './screens/Example6'
1010
import Example7 from './screens/Example7'
11+
import Example8 from './screens/Example8'
1112

1213
import TableViewExampleCell from './cells/TableViewExampleCell'
1314

14-
const Stack = StackNavigator(
15+
const Stack = createStackNavigator(
1516
{
1617
home: {
1718
screen: Home,
@@ -61,6 +62,12 @@ const Stack = StackNavigator(
6162
title: 'Pull to Refresh',
6263
},
6364
},
65+
index: {
66+
screen: Example8,
67+
navigationOptions: {
68+
title: 'Scroll to Index',
69+
},
70+
},
6471
},
6572
{
6673
navigationOptions: {

example/src/screens/Example8.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react'
2+
import { Button, View } from 'react-native'
3+
import TableView from 'react-native-tableview'
4+
5+
const { Section, Item } = TableView
6+
7+
class Example8 extends React.Component{
8+
render() {
9+
return(
10+
<View style={{flex: 1}}>
11+
12+
<Button title="Scroll To Section 2" onPress={() => this.tableView.scrollToIndex({index: 2, section: 1})} />
13+
14+
<TableView
15+
style={{ flex: 1 }}
16+
allowsToggle
17+
ref={ref => this.tableView = ref}
18+
allowsMultipleSelection
19+
tableViewStyle={TableView.Consts.Style.Grouped}
20+
tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
21+
onPress={event => console.log(event)}
22+
>
23+
<Section label="Section 1" arrow>
24+
<Item value="1" detail="Detail1">
25+
Item 1
26+
</Item>
27+
<Item value="2">Item 2</Item>
28+
<Item>Item 3</Item>
29+
</Section>
30+
31+
<Section label="Section 2" arrow={false}>
32+
<Item>Item 1</Item>
33+
<Item>Item 2</Item>
34+
<Item>Item 3</Item>
35+
</Section>
36+
37+
<Section label="Section 3" arrow={false}>
38+
<Item>Item 1</Item>
39+
<Item>Item 2</Item>
40+
<Item>Item 3</Item>
41+
<Item>Item 4</Item>
42+
<Item>Item 5</Item>
43+
<Item>Item 6</Item>
44+
<Item>Item 7</Item>
45+
<Item>Item 8</Item>
46+
<Item>Item 9</Item>
47+
<Item>Item 10</Item>
48+
</Section>
49+
</TableView>
50+
</View>
51+
)
52+
}
53+
}
54+
55+
export default Example8

example/src/screens/Home.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const App = ({ navigation }: NavigationScreenConfigProps) => {
2727
<Item onPress={() => navigate('custom')}>Custom Cells</Item>
2828
<Item onPress={() => navigate('edit', { editing: true })}>Editing mode</Item>
2929
<Item onPress={() => navigate('refresh')}>Pull to Refresh</Item>
30+
<Item onPress={() => navigate('index')}>Scroll To Index</Item>
3031
</Section>
3132
</TableView>
3233
)

0 commit comments

Comments
 (0)