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

WIP - react-native module #25

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
aced205
feat(rnmod): init workspace and example app
n0izn0iz Dec 18, 2019
01ba07a
feat(rnmod): working android module with std ipfs syntax
n0izn0iz Dec 18, 2019
626b7cd
feat(rnmod): update README
n0izn0iz Dec 18, 2019
549a726
feat(rnmod): rename pkg
n0izn0iz Dec 18, 2019
7e376b0
feat(rnmod): include local_repo in pkg archive for now
n0izn0iz Dec 18, 2019
ecbf1de
feat(rnmod): clean a bit
n0izn0iz Dec 19, 2019
e2d9936
feat(rnmod): asynchronous android implementation + fix instance handle
n0izn0iz Dec 20, 2019
4643ff3
feat(rnmod): finish makefile + edit package metadata
n0izn0iz Dec 20, 2019
90d2a99
feat(rnmod): edit package.json to not bother other team members + add…
n0izn0iz Dec 20, 2019
df201fc
feat(rnmod): ios implementation
jembijemb Dec 24, 2019
1d59dd3
feat(rnmod): clean and make package publishable
jembijemb Dec 24, 2019
22f43d4
feat(rnmod): update readme
jembijemb Dec 30, 2019
83ef51f
feat(rnmod): npmignore apple local files
jembijemb Dec 30, 2019
5c9cee2
feat(rnmod): publish package (version bump)
jembijemb Dec 30, 2019
02d3964
fix(rnmod/make): clean yarn cache to prevent reinstallation of same v…
n0izn0iz Jan 30, 2020
83ec739
fix(rnmod/gradle): add missing dependencies
n0izn0iz Jan 30, 2020
a544488
fix(rnmod/android): use RequestBuilder
n0izn0iz Jan 30, 2020
9f454f6
refactor(rnmod/android): don't transform uuid
n0izn0iz Jan 30, 2020
fc07250
chore(rnmod): bump minor version
n0izn0iz Jan 30, 2020
330bce6
chore(rnmod): update package.json repository
n0izn0iz Jan 30, 2020
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
1 change: 1 addition & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
react-native-go-ipfs.tgz
50 changes: 50 additions & 0 deletions js/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ALL_NODE_MODULES=node_modules $(wildcard */node_modules)
POD_NAME=GomobileIPFS
MODULE_NAME=react-native-go-ipfs
LOCAL_REPO=$(MODULE_NAME)/android/local_repo
BRIDGE_VERSION=0.0.1
GOMOBILE_IPFS_VERSION=0.0.1
LOCAL_BRIDGE_DIR=$(LOCAL_REPO)/ipfs/gomobile/android/$(BRIDGE_VERSION)
LOCAL_GOMOBILE_IPFS_DIR=$(LOCAL_REPO)/ipfs/gomobile/gomobile-ipfs/$(GOMOBILE_IPFS_VERSION)
ARCHIVE=$(MODULE_NAME).tgz
LOCAL_POD=$(MODULE_NAME)/ios/$(POD_NAME)

.PHONY: run.%
run.%:
cd app && ./node_modules/.bin/react-native run-$*

.PHONY: deps.android
deps.android:
$(MAKE) -C .. build.android
cd ../android && ./gradlew bridge:build

rm -fr $(LOCAL_REPO)
cp -R ../android/local_repo $(LOCAL_REPO)
mkdir -p $(LOCAL_BRIDGE_DIR)
cp ../android/bridge/build/outputs/aar/bridge-debug.aar $(LOCAL_BRIDGE_DIR)/android-$(BRIDGE_VERSION).aar
cp $(LOCAL_GOMOBILE_IPFS_DIR)/gomobile-ipfs-0.0.1.pom $(LOCAL_BRIDGE_DIR)/android-0.0.1.pom
sed -i.bak 's/<artifactId>gomobile-ipfs<\/artifactId>/<artifactId>android<\/artifactId>/' $(LOCAL_BRIDGE_DIR)/android-0.0.1.pom

cd $(MODULE_NAME) && yarn pack --filename ../$(ARCHIVE)
cd app && yarn remove react-native-go-ipfs || true
yarn cache clean
cd app && yarn add file:../$(ARCHIVE)


.PHONY: deps.ios
deps.ios:
$(MAKE) -C .. build.ios

rm -fr $(LOCAL_POD)
mkdir -p $(LOCAL_POD)
cp -R ../ios/$(POD_NAME) ../ios/Frameworks ../ios/$(POD_NAME).podspec ../ios/LICENSE $(LOCAL_POD)

cd $(MODULE_NAME) && yarn pack --filename ../$(ARCHIVE)
cd app && yarn remove react-native-go-ipfs || true
yarn cache clean
cd app && yarn add file:../$(ARCHIVE)
cd app/ios && pod install

.PHONY: clean
clean:
rm -fr $(LOCAL_REPO) $(LOCAL_POD) $(ALL_NODE_MODULES) $(ARCHIVE)
6 changes: 6 additions & 0 deletions js/app/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
4 changes: 4 additions & 0 deletions js/app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
75 changes: 75 additions & 0 deletions js/app/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore polyfills
node_modules/react-native/Libraries/polyfills/.*

; These should not be required directly
; require from fbjs/lib instead: require('fbjs/lib/warning')
node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/

[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

munge_underscores=true

module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation'
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
inexact-spread=warn
unnecessary-invariant=warn
signature-verification-failure=warn
deprecated-utility=error

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.105.0
1 change: 1 addition & 0 deletions js/app/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
59 changes: 59 additions & 0 deletions js/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
6 changes: 6 additions & 0 deletions js/app/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};
1 change: 1 addition & 0 deletions js/app/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
156 changes: 156 additions & 0 deletions js/app/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/

import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Button,
NativeModules,
} from 'react-native';

import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

import IPFS from 'react-native-go-ipfs';

function uuidv4() {
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

const test = async () => {
const testId = uuidv4();

console.log('Starting IPFS test:', testId);

const ipfs = new IPFS();
console.log('Constructed IPFS object:', ipfs, ` (testId: ${testId})`);

console.log('Starting ipfs instance:', ipfs, ` (testId: ${testId})`);
await ipfs.start();
console.log(
'Started ipfs instance',
ipfs.nativeHandle,
` (testId: ${testId})`,
);

const {ID} = await ipfs.id();
console.log(
`Executed command /id on instance ${
ipfs.nativeHandle
}, got ID=${ID} (testId: ${testId})`,
);

const handle = ipfs.nativeHandle;
await ipfs.stop();
console.log('Stopped ipfs instance', handle, ` (testId: ${testId})`);
};

const App: () => React$Node = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<Button onPress={test} title="IPFS Test" />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<Header />
{global.HermesInternal == null ? null : (
<View style={styles.engine}>
<Text style={styles.footer}>Engine: Hermes</Text>
</View>
)}
<View style={styles.body}>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Step One</Text>
<Text style={styles.sectionDescription}>
Edit <Text style={styles.highlight}>App.js</Text> to change this
screen and then come back to see your edits.
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>See Your Changes</Text>
<Text style={styles.sectionDescription}>
<ReloadInstructions />
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Debug</Text>
<Text style={styles.sectionDescription}>
<DebugInstructions />
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Learn More</Text>
<Text style={styles.sectionDescription}>
Read the docs to discover what to do next:
</Text>
</View>
<LearnMoreLinks />
</View>
</ScrollView>
</SafeAreaView>
</>
);
};

const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});

export default App;
14 changes: 14 additions & 0 deletions js/app/__tests__/App-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
});
Loading