Skip to content

Commit

Permalink
Merge pull request #2 from wordpress-mobile/feature/stub_implementati…
Browse files Browse the repository at this point in the history
…on_of_list_on_iOS

Feature/stub implementation of list on iOS
  • Loading branch information
SergioEstevao authored Apr 24, 2018
2 parents 2379e8d + cce6250 commit 1305dd3
Show file tree
Hide file tree
Showing 17 changed files with 1,055 additions and 894 deletions.
145 changes: 132 additions & 13 deletions example/App.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,145 @@ import {
AppRegistry,
StyleSheet,
Text,
View
View,
Image,
Button,
TouchableNativeFeedback
} from 'react-native';

export default class example extends Component {
import RecyclerViewList, { DataSource } from 'react-native-recyclerview-list';

var _gCounter = 1;
function newItem() {
return {
id: _gCounter++,
counter: 0
};
}

export default class example extends Component {

constructor(props) {
super(props);
var data = Array(10).fill().map((e,i) => newItem());

this.state = {
dataSource: new DataSource(data, (item, index) => item.id)
};
}

render() {
const { dataSource } = this.state;

return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<View style={{flex:1}}>
{ this.renderTopControlPanel() }
<RecyclerViewList
ref={(component) => this._recycler = component}
style={{flex:1}}
dataSource={dataSource}
/>
{ this.renderBottomControlPanel() }
</View>
);
}

renderTopControlPanel() {
return (
<View style={{ flexDirection: 'row', padding: 5, alignItems: 'center', justifyContent: 'center', backgroundColor: '#e7e7e7' }}>
<Button
title={"\u002B40 \u25B2"}
onPress={() => this.addToTop(40)} />
<View style={{ width: 5 }} />
<Button
title={"\u002B40 \u25BC"}
onPress={() => this.addToBottom(40)} />
<View style={{ width: 15 }} />
<Text>Scroll:</Text>
<View style={{ width: 5 }} />
<Button
title={"\u25B2"}
onPress={() => this._recycler && this._recycler.scrollToIndex({index: 0, animated: true})} />
<View style={{ width: 5 }} />
<Button
title={"\u25BC"}
onPress={() => this._recycler && this._recycler.scrollToEnd()} />
<View style={{ width: 5 }} />
<Button
title={"rand"}
onPress={() => {
var index = Math.floor((Math.random() * this.state.dataSource.size()));
var item = this.state.dataSource.get(index);
this._recycler && this._recycler.scrollToIndex({ index, animated: true });
}} />
</View>
);
}

renderBottomControlPanel() {
return (
<View style={{ flexDirection: 'row', padding: 5, alignItems: 'center', justifyContent: 'center', backgroundColor: '#e7e7e7' }}>
<Button
title={"Reset"}
onPress={() => this.reset()} />
</View>
);
}

reset() {
//_gCounter = 1;
var data = Array(10).fill().map((e,i) => newItem());
this.setState({
dataSource: new DataSource(data, (item, index) => item.id)
});
}

remove(index) {
this.state.dataSource.splice(index, 1);
}

addAbove(index) {
this.state.dataSource.splice(index, 0, newItem());
}

addBelow(index) {
const { dataSource } = this.state;
if (index == dataSource.size() - 1 && this._recycler) {
this._recycler.scrollToIndex({
animated: true,
index: dataSource.size(),
velocity: 120
});
}

this.state.dataSource.splice(index+1, 0, newItem());
}

incrementCounter(index) {
var item = this.state.dataSource.get(index);
item.counter++;
this.state.dataSource.set(index, item);
}

moveUp(index) {
this.state.dataSource.moveUp(index);
}

moveDown(index) {
this.state.dataSource.moveDown(index);
}

addToTop(size) {
var currCount = this.state.dataSource.size();
var newItems = Array(size).fill().map((e,i)=>newItem());
this.state.dataSource.splice(0, 0, ...newItems);
}

addToBottom(size) {
var currCount = this.state.dataSource.size();
var newItems = Array(size).fill().map((e,i)=>newItem());
this.state.dataSource.splice(currCount, 0, ...newItems);
}
}

const styles = StyleSheet.create({
Expand Down
2 changes: 1 addition & 1 deletion example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Apr 11 08:23:04 CEST 2018
#Thu Apr 19 14:25:25 BST 2018
connection.project.dir=
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Apr 11 08:23:05 CEST 2018
#Thu Apr 19 14:25:25 BST 2018
connection.project.dir=..
4 changes: 4 additions & 0 deletions example/ios/example-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

26 changes: 26 additions & 0 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
FF658117208F4C5B0034D916 /* empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF658116208F4C5B0034D916 /* empty.swift */; };
FFEECFF92084A480009B8CDB /* src in Resources */ = {isa = PBXBuildFile; fileRef = FFEECFF82084A480009B8CDB /* src */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -351,6 +353,11 @@
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
FF658115208F4C5B0034D916 /* example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "example-Bridging-Header.h"; sourceTree = "<group>"; };
FF658116208F4C5B0034D916 /* empty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = empty.swift; path = example/empty.swift; sourceTree = "<group>"; };
FFEECFF82084A480009B8CDB /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = ../../src; sourceTree = "<group>"; };
FFEECFFF2088CDE8009B8CDB /* App.android.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = App.android.js; path = ../App.android.js; sourceTree = "<group>"; };
FFEED0002088CDE8009B8CDB /* App.ios.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = App.ios.js; path = ../App.ios.js; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -497,6 +504,8 @@
13B07FB61A68108700A75B9A /* Info.plist */,
13B07FB11A68108700A75B9A /* LaunchScreen.xib */,
13B07FB71A68108700A75B9A /* main.m */,
FF658116208F4C5B0034D916 /* empty.swift */,
FF658115208F4C5B0034D916 /* example-Bridging-Header.h */,
);
name = example;
sourceTree = "<group>";
Expand Down Expand Up @@ -590,6 +599,9 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
FFEECFFF2088CDE8009B8CDB /* App.android.js */,
FFEED0002088CDE8009B8CDB /* App.ios.js */,
FFEECFF82084A480009B8CDB /* src */,
13B07FAE1A68108700A75B9A /* example */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* exampleTests */,
Expand Down Expand Up @@ -709,6 +721,9 @@
CreatedOnToolsVersion = 6.2;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
LastSwiftMigration = 0930;
};
2D02E47A1E0B4A5D006451C7 = {
CreatedOnToolsVersion = 8.2.1;
ProvisioningStyle = Automatic;
Expand Down Expand Up @@ -1076,6 +1091,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FFEECFF92084A480009B8CDB /* src in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
);
Expand Down Expand Up @@ -1144,6 +1160,7 @@
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
FF658117208F4C5B0034D916 /* empty.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1195,6 +1212,7 @@
00E356F61AD99517003FC87E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -1215,6 +1233,7 @@
00E356F71AD99517003FC87E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = exampleTests/Info.plist;
Expand All @@ -1233,6 +1252,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = NO;
INFOPLIST_FILE = example/Info.plist;
Expand All @@ -1243,6 +1263,9 @@
"-lc++",
);
PRODUCT_NAME = example;
SWIFT_OBJC_BRIDGING_HEADER = "example-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand All @@ -1251,6 +1274,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1260,6 +1284,8 @@
"-lc++",
);
PRODUCT_NAME = example;
SWIFT_OBJC_BRIDGING_HEADER = "example-Bridging-Header.h";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
9 changes: 9 additions & 0 deletions example/ios/example/empty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// empty.swift
// example
//
// Created by Sergio Estevao on 24/04/2018.
// Copyright © 2018 Facebook. All rights reserved.
//

import Foundation
Loading

0 comments on commit 1305dd3

Please sign in to comment.