diff --git a/CHANGELOG.md b/CHANGELOG.md index dd85c462cb..35e156e541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ x.x.x Release notes (yyyy-MM-dd) * Updated Docker URL to new canonical URL of `ghcr.io` * Excluding the `react-native/android/build` directory from the NPM package. * Removed the `examples/ReactExample` app. See [FindOurDevices](https://github.com/realm/FindOurDevices) for a modern example app. +* Removed undocumented, outdated and unused `ListView` component exported via `realm/react-native`. See [@realm.io/react](https://www.npmjs.com/package/@realm.io/react) for a modern integration with React. * * * diff --git a/react-native/.eslintrc.json b/react-native/.eslintrc.json deleted file mode 100644 index 6be29d5aea..0000000000 --- a/react-native/.eslintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "@react-native-community", - "../.eslintrc" - ] -} \ No newline at end of file diff --git a/react-native/android/build.gradle b/react-native/android/build.gradle index 06f03c81f6..7a24ddf822 100644 --- a/react-native/android/build.gradle +++ b/react-native/android/build.gradle @@ -70,7 +70,7 @@ apply from: 'analytics.gradle' import groovy.json.JsonSlurper def getPackageVersion() { - def inputFile = new File(buildscript.sourceFile.getParent() + "/../package.json") + def inputFile = new File(buildscript.sourceFile.getParent() + "/../../package.json") def packageJson = new JsonSlurper().parseText(inputFile.text) return packageJson["version"] } diff --git a/react-native/index.js b/react-native/index.js deleted file mode 100644 index 5ecf61055d..0000000000 --- a/react-native/index.js +++ /dev/null @@ -1,21 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 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. -// -//////////////////////////////////////////////////////////////////////////// - -import ListView from "./listview"; - -export { ListView }; diff --git a/react-native/listview.js b/react-native/listview.js deleted file mode 100644 index f9c1bddee9..0000000000 --- a/react-native/listview.js +++ /dev/null @@ -1,200 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 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. -// -//////////////////////////////////////////////////////////////////////////// - -import React from "react"; -import PropTypes from "prop-types"; -import ReactNativeListView from "deprecated-react-native-listview"; - -function hashObjects(array) { - let hash = Object.create(null); - for (let i = 0, len = array.length; i < len; i++) { - hash[array[i]] = true; - } - return hash; -} - -class DataSource extends ReactNativeListView.DataSource { - cloneWithRowsAndSections(inputData, sectionIds, rowIds) { - let data = {}; - - for (let sectionId in inputData) { - let items = inputData[sectionId]; - let copy; - - // Realm Results and List objects have a snapshot() method. - if (typeof items.snapshot === "function") { - copy = items.snapshot(); - } else if (Array.isArray(items)) { - copy = items.slice(); - } else { - copy = Object.assign({}, items); - } - - data[sectionId] = copy; - } - - if (!sectionIds) { - sectionIds = Object.keys(data); - } - if (!rowIds) { - rowIds = sectionIds.map((sectionId) => { - let items = data[sectionId]; - if (typeof items.snapshot !== "function") { - return Object.keys(items); - } - - // Efficiently get the keys of the Realm collection, since they're never sparse. - let count = items.length; - let indexes = new Array(count); - for (let i = 0; i < count; i++) { - indexes[i] = i; - } - return indexes; - }); - } - - // Copy this object with the same parameters initially passed into the constructor. - let newSource = new this.constructor({ - getRowData: this._getRowData, - getSectionHeaderData: this._getSectionHeaderData, - rowHasChanged: this._rowHasChanged, - sectionHeaderHasChanged: this._sectionHeaderHasChanged, - }); - - newSource._cachedRowCount = rowIds.reduce((n, a) => n + a.length, 0); - newSource._dataBlob = data; - newSource.sectionIdentities = sectionIds; - newSource.rowIdentities = rowIds; - - let prevSectionIds = this.sectionIdentities; - let prevRowIds = this.rowIdentities; - let prevRowHash = {}; - for (let i = 0, len = prevRowIds.length; i < len; i++) { - prevRowHash[prevSectionIds[i]] = hashObjects(prevRowIds[i]); - } - - // These properties allow lazily calculating if rows and section headers should update. - newSource._prevDataBlob = this._dataBlob; - newSource._prevSectionHash = hashObjects(prevSectionIds); - newSource._prevRowHash = prevRowHash; - - return newSource; - } - - getRowData() { - // The React.ListView calls this for *every* item during each render, which is quite - // premature since this can be mildly expensive and memory inefficient since it keeps - // the result of this alive through a bound renderRow function. - return null; - } - - getRow(sectionId, rowId) { - // This new method is provided as a convenience for those wishing to be memory efficient. - return this._getRowData(this._dataBlob, sectionId, rowId); - } - - sectionHeaderShouldUpdate(sectionIndex) { - let dirtySections = this._dirtySections; - let dirty; - - if ((dirty = dirtySections[sectionIndex]) != null) { - // This was already calculated before. - return dirty; - } - - let sectionId = this.sectionIdentities[sectionIndex]; - let sectionHeaderHasChanged = this._sectionHeaderHasChanged; - if (this._prevSectionHash[sectionId] && sectionHeaderHasChanged) { - dirty = sectionHeaderHasChanged( - this._getSectionHeaderData(this._prevDataBlob, sectionId), - this._getSectionHeaderData(this._dataBlob, sectionId), - ); - } - - // Unless it's explicitly *not* dirty, then this section header should update. - return (dirtySections[sectionIndex] = dirty !== false); - } - - rowShouldUpdate(sectionIndex, rowIndex) { - let dirtyRows = this._dirtyRows[sectionIndex]; - let dirty; - - if (!dirtyRows) { - dirtyRows = this._dirtyRows[sectionIndex] = []; - } else if ((dirty = dirtyRows[rowIndex]) != null) { - // This was already calculated before. - return dirty; - } - - let sectionId = this.sectionIdentities[sectionIndex]; - if (this._prevSectionHash[sectionId]) { - let rowId = this.rowIdentities[sectionIndex][rowIndex]; - if (this._prevRowHash[sectionId][rowId]) { - let prevItem = this._getRowData(this._prevDataBlob, sectionId, rowId); - if (prevItem) { - let item = this._getRowData(this._dataBlob, sectionId, rowId); - if (item) { - dirty = this._rowHasChanged(prevItem, item); - } - } - } - } - - // Unless it's explicitly *not* dirty, then this row should update. - return (dirtyRows[rowIndex] = dirty !== false); - } -} - -export default class ListView extends React.Component { - constructor(props) { - super(props); - - this.renderRow = this.renderRow.bind(this); - } - - render() { - return ; - } - - renderRow(_, sectionId, rowId, ...args) { - let props = this.props; - let item = props.dataSource.getRow(sectionId, rowId); - - // The item could be null because our data is a snapshot and it was deleted. - return item ? props.renderRow(item, sectionId, rowId, ...args) : null; - } - - getInnerViewNode() { - return this.refs.listView.getInnerViewNode(); - } - - scrollTo(...args) { - this.refs.listView.scrollTo(...args); - } - - setNativeProps(props) { - this.refs.listView.setNativeProps(props); - } -} - -ListView.propTypes = { - dataSource: PropTypes.instanceOf(DataSource).isRequired, - renderRow: PropTypes.func.isRequired, -}; - -ListView.DataSource = DataSource; diff --git a/react-native/package.json b/react-native/package.json deleted file mode 100644 index 1bb9506e57..0000000000 --- a/react-native/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "realm-react-native", - "version": "0.0.1", - "main": "index.js", - "private": true, - "dependencies": { - "react": "16.6.3", - "react-native": "0.58.5" - } -} diff --git a/tests/ReactTestApp/tests/index.js b/tests/ReactTestApp/tests/index.js index c427ca1559..4fca8e5620 100644 --- a/tests/ReactTestApp/tests/index.js +++ b/tests/ReactTestApp/tests/index.js @@ -20,11 +20,6 @@ import {NativeEventEmitter, NativeModules} from 'react-native'; import * as RealmTests from 'realm-tests'; -import ListViewTest from './listview-test'; - -RealmTests.registerTests({ - ListViewTest, -}); const realmTestEmitter = new NativeEventEmitter( NativeModules.RealmTestEventEmitter, diff --git a/tests/ReactTestApp/tests/listview-test.js b/tests/ReactTestApp/tests/listview-test.js deleted file mode 100644 index 561ce4222d..0000000000 --- a/tests/ReactTestApp/tests/listview-test.js +++ /dev/null @@ -1,96 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 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 Realm from 'realm'; -import {ListView} from 'realm/react-native'; -import {assertEqual, assertTrue} from 'realm-tests/asserts'; - -const OBJECT_SCHEMA = { - name: 'UniqueObject', - primaryKey: 'id', - properties: { - id: 'int', - }, -}; - -function createRealm() { - let realm = new Realm({schema: [OBJECT_SCHEMA]}); - - realm.write(() => { - for (let i = 0; i < 10; i++) { - realm.create('UniqueObject', {id: i}); - } - }); - - return realm; -} - -function createDataSource() { - return new ListView.DataSource({ - rowHasChanged: (a, b) => a.id !== b.id, - }); -} - -export default { - testDataSource() { - let realm = createRealm(); - let objects = realm.objects('UniqueObject').sorted('id'); - let dataSource = createDataSource().cloneWithRows(objects); - let count = objects.length; - - // Make sure the section header should update. - assertTrue(dataSource.sectionHeaderShouldUpdate(0)); - - // All rows should need to update. - for (let i = 0; i < count; i++) { - assertTrue(dataSource.rowShouldUpdate(0, i)); - } - - // Clone data source with no changes and make sure no rows need to update. - dataSource = dataSource.cloneWithRows(objects); - for (let i = 0; i < count; i++) { - assertTrue(!dataSource.rowShouldUpdate(0, i)); - } - - // Delete the second object and make sure current data source is unchanged. - realm.write(() => realm.delete(objects[1])); - for (let i = 0; i < count; i++) { - assertTrue(!dataSource.rowShouldUpdate(0, i)); - } - - // Getting the row data for the second row should return null. - assertEqual(dataSource.getRow('s1', 1), null); - - // Clone data source and make sure all rows after the first one need to update. - dataSource = dataSource.cloneWithRows(objects); - for (let i = 0; i < count - 1; i++) { - let changed = dataSource.rowShouldUpdate(0, i); - assertTrue(i == 0 ? !changed : changed); - } - - // Create an object at the ened and make sure only the last row needs to update. - realm.write(() => realm.create('UniqueObject', {id: count})); - dataSource = dataSource.cloneWithRows(objects); - for (let i = 0; i < count; i++) { - let changed = dataSource.rowShouldUpdate(0, i); - assertTrue(i < count - 1 ? !changed : changed); - } - }, -};