Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 9 fixes #1483

Merged
merged 18 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ tests/realm-object-server/
packager_out.txt
build.log.*
realm-object-server/
tests/react-test-app/ios/out.txt
*.iml
1 change: 1 addition & 0 deletions examples/ReactExample/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ android {
}

dependencies {
compile project(':react-native-exit-app-no-history')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.github.wumke.RNExitApp.RNExitAppPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
Expand All @@ -27,6 +28,7 @@ protected boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNExitAppPackage(),
new RealmReactPackage()
);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/ReactExample/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'ReactExample'
include ':react-native-exit-app-no-history'
project(':react-native-exit-app-no-history').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app-no-history/android')

include ':app'

Expand Down
63 changes: 63 additions & 0 deletions examples/ReactExample/components/items-screen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2017 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

'use strict';

import React from 'react';

import {
Platform,
StatusBar,
Text,
TouchableOpacity,
View,
} from 'react-native';

import TodoItem from './todo-item';
import TodoListView from './todo-listview';
import TodoItemsView from './todo-itemsview';
import TodoListItem from './todo-list-item';
import realm from './realm';
import styles from './styles';

import { StackNavigator } from 'react-navigation';

export default class ItemsScreen extends React.Component {
static navigationOptions = {
title: 'Current list',
};

constructor(props) {
super(props);
this.state = {};
}

componentWillMount() {
if (Platform.OS == 'ios') {
StatusBar.setBarStyle('light-content');
}
}

render() {

let properties = {
}

return <TodoItemsView items={this.props.navigation.state.params.items} {...properties} />;
}
}
1 change: 1 addition & 0 deletions examples/ReactExample/components/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 3 additions & 4 deletions examples/ReactExample/components/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
'use strict';

import {
Navigator,
Platform,
StyleSheet
} from 'react-native';

const { NavBarHeight, TotalNavHeight } = Navigator.NavigationBar.Styles.General;
const iOS = (Platform.OS == 'ios');


export default StyleSheet.create({
container: {
flex: 1,
Expand All @@ -43,7 +42,7 @@ export default StyleSheet.create({
navBarView: {
alignItems: 'center',
flexDirection: 'row',
height: NavBarHeight,
height: 20,
},
navBarLeftArrow: {
color: '#fff',
Expand All @@ -66,7 +65,7 @@ export default StyleSheet.create({
fontWeight: '500',
},
navScene: {
top: TotalNavHeight,
top: 20,
},
listItem: {
borderColor: '#c8c7cc',
Expand Down
135 changes: 36 additions & 99 deletions examples/ReactExample/components/todo-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import React from 'react';

import {
Navigator,
Platform,
StatusBar,
Text,
Expand All @@ -31,28 +30,42 @@ import {

import TodoItem from './todo-item';
import TodoListView from './todo-listview';
import TodoListItem from './todo-list-item';
import ItemsScreen from './items-screen'
import realm from './realm';
import styles from './styles';

export default class TodoApp extends React.Component {
import { StackNavigator } from 'react-navigation';
import RNExitApp from 'react-native-exit-app-no-history';

const params = require("./params.json");

class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Todo Lists',
};

constructor(props) {
super(props);

// This is a Results object, which will live-update.
this.todoLists = realm.objects('TodoList').sorted('creationDate');
if (this.todoLists.length < 1) {
realm.write(() => {
realm.create('TodoList', {name: 'Todo List', creationDate: new Date()});
realm.create('TodoList', { name: 'Todo List', creationDate: new Date() });
});
}
this.todoLists.addListener((name, changes) => {
console.log("changed: " + JSON.stringify(changes));
if (params) {
console.error("params.json indicates a test run. Exiting application");
RNExitApp.exitApp();
}
});
console.log("registered listener");


// Bind all the methods that we will be passing as props.
this.renderScene = this.renderScene.bind(this);
this._addNewTodoList = this._addNewTodoList.bind(this);
this._onPressTodoList = this._onPressTodoList.bind(this);

Expand All @@ -73,37 +86,17 @@ export default class TodoApp extends React.Component {
render() {
let objects = realm.objects('Todo');
let extraItems = [
{name: 'Complete', items: objects.filtered('done = true')},
{name: 'Incomplete', items: objects.filtered('done = false')},
{ name: 'Complete', items: objects.filtered('done = true') },
{ name: 'Incomplete', items: objects.filtered('done = false') },
];

let route = {
title: 'My Todo Lists',
component: TodoListView,
passProps: {
ref: 'listView',
extraItems: extraItems,
onPressItem: this._onPressTodoList,
},
backButtonTitle: 'Lists',
rightButtonTitle: 'Add',
onRightButtonPress: this._addNewTodoList,
};

let navigationBar = (
<Navigator.NavigationBar routeMapper={RouteMapper} style={styles.navBar} />
);

return (
<Navigator
ref="nav"
initialRoute={route}
navigationBar={navigationBar}
renderScene={this.renderScene}
sceneStyle={styles.navScene}
style={styles.navigator}
/>
);
let properties = {
ref: 'listView',
extraItems: extraItems,
onPressItem: this._onPressTodoList,
}

return <TodoListView items={this.todoLists} {...properties} />;
}

renderScene(route) {
Expand All @@ -118,7 +111,7 @@ export default class TodoApp extends React.Component {
}

realm.write(() => {
items.push({text: ''});
items.push({ text: '' });
});

this._setEditingRow(items.length - 1);
Expand All @@ -131,34 +124,17 @@ export default class TodoApp extends React.Component {
}

realm.write(() => {
realm.create('TodoList', {name: '', creationDate: new Date()});
realm.create('TodoList', { name: '', creationDate: new Date() });
});

this._setEditingRow(items.length - 1);
}

_onPressTodoList(list) {
const { navigate } = this.props.navigation;
let items = list.items;

let route = {
title: list.name,
component: TodoListView,
passProps: {
ref: 'listItemView',
items: items,
rowClass: TodoItem,
},
};

// Check if the items are mutable (i.e. List rather than Results).
if (items.push) {
Object.assign(route, {
rightButtonTitle: 'Add',
onRightButtonPress: () => this._addNewTodoItem(list),
});
}

this.refs.nav.push(route);
navigate('ItemsScreen', { items: items })
}

_shouldAddNewItem(items) {
Expand All @@ -173,53 +149,14 @@ export default class TodoApp extends React.Component {
let listView = this.currentListView;

// Update the state on the currently displayed TodoList to edit this new item.
listView.setState({editingRow: rowIndex});
listView.setState({ editingRow: rowIndex });
listView.updateDataSource();
}
}

const RouteMapper = {
LeftButton(route, navigator, index, navState) {
if (index == 0) {
return null;
}

let prevRoute = navState.routeStack[index - 1];
return (
<TouchableOpacity onPress={() => navigator.pop()}>
<View style={[styles.navBarView, styles.navBarLeftButton]}>
<Text style={styles.navBarLeftArrow}>‹</Text>
<Text style={styles.navBarText}>
{prevRoute.backButtonTitle || prevRoute.title || 'Back'}
</Text>
</View>
</TouchableOpacity>
);
},

RightButton(route) {
if (!route.rightButtonTitle) {
return null;
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
ItemsScreen: { screen: ItemsScreen }
});

return (
<TouchableOpacity onPress={route.onRightButtonPress}>
<View style={[styles.navBarView, styles.navBarRightButton]}>
<Text style={styles.navBarText}>
{route.rightButtonTitle}
</Text>
</View>
</TouchableOpacity>
);
},

Title(route) {
return (
<View style={styles.navBarView}>
<Text style={[styles.navBarText, styles.navBarTitleText]}>
{route.title}
</Text>
</View>
);
},
};
export default SimpleApp;
Loading