textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
302 lines (292 loc) • 16.6 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@textile/react-native-sdk - v3.1.4</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@textile/react-native-sdk - v3.1.4</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<li>
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> @textile/react-native-sdk - v3.1.4</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#react-native-textile" id="react-native-textile" style="color: inherit; text-decoration: none;">
<h1>React Native Textile</h1>
</a>
<a href="#installation" id="installation" style="color: inherit; text-decoration: none;">
<h2>Installation</h2>
</a>
<p><code>npm install @textile/react-native-sdk --save</code></p>
<p><strong>Link the Framework</strong></p>
<p><code>react-native link @textile/react-native-sdk</code></p>
<p>Note: The iOS component of <code>@textile/react-native-sdk</code> should be installed using Cocoapods. Newer versions of React Native will auto link the library, and <code>react-native link</code> can be run otherwise.</p>
<p><strong>Update Android Gradle</strong></p>
<p>You'll need to add Textile's maven repository to your project <code>build.gradle</code>'s <code>allProjects.repositories</code> section:</p>
<pre><code><span class="hljs-section">maven</span> { <span class="hljs-attribute">url</span> <span class="hljs-string">"https://dl.bintray.com/textile/maven"</span> }</code></pre><p><strong>Other dependencies</strong></p>
<p>The Textile library also requires that your project has two other libraries installed. Following the installation instructions for the following two,</p>
<ol>
<li><a href="https://github.com/transistorsoft/react-native-background-fetch">react-native-background-fetch</a></li>
<li><a href="https://github.com/ocetnik/react-native-background-timer">react-native-background-timer</a></li>
</ol>
<a href="#typescript-types" id="typescript-types" style="color: inherit; text-decoration: none;">
<h3>Typescript Types</h3>
</a>
<p>@textile/react-native-sdk is written in TypeScript and compiled to JavaScript. You can use either in your app.</p>
<a href="#examples" id="examples" style="color: inherit; text-decoration: none;">
<h2>Examples</h2>
</a>
<a href="#react-native-boilerplate" id="react-native-boilerplate" style="color: inherit; text-decoration: none;">
<h3>React Native Boilerplate</h3>
</a>
<p>To jump right into a working app, see our demo <a href="https://github.com/textileio/react-native-boilerplate">IPFS boilerplate app</a>.</p>
<a href="#advanced-boilerplate" id="advanced-boilerplate" style="color: inherit; text-decoration: none;">
<h3>Advanced Boilerplate</h3>
</a>
<p>We also have a more advanced boilerplate that contains <code>react-navigation</code>, redux, and sagas together with Textile. Find that here, <a href="https://github.com/textileio/advanced-react-native-boilerplate/tree/master">advanced-react-native-boilerplate</a>.</p>
<a href="#run-textile" id="run-textile" style="color: inherit; text-decoration: none;">
<h2>Run Textile</h2>
</a>
<p>At a minimum, you'll need to initialize Textile if required, then launch Textile. You'll also probably want to subscribe to many of the events emitted by Textile. You can see this below:</p>
<pre><code class="language-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> {
SafeAreaView,
Text,
StatusBar,
} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
<span class="hljs-keyword">import</span> FS <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native-fs'</span>;
<span class="hljs-keyword">import</span> Textile <span class="hljs-keyword">from</span> <span class="hljs-string">'@textile/react-native-sdk'</span>;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">App</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
<span class="hljs-keyword">constructor</span>(props) {
<span class="hljs-keyword">super</span>(props);
<span class="hljs-keyword">this</span>.state = {<span class="hljs-attr">version</span>: <span class="hljs-string">""</span>};
}
componentDidMount() {
<span class="hljs-keyword">this</span>.setup();
}
<span class="hljs-keyword">async</span> setup() {
Textile.events.addNodeOnlineListener(<span class="hljs-keyword">this</span>.nodeOnline);
<span class="hljs-keyword">const</span> repoPath = <span class="hljs-string">`<span class="hljs-subst">${FS.DocumentDirectoryPath}</span>/textile-go`</span>;
<span class="hljs-keyword">const</span> initialized = <span class="hljs-keyword">await</span> Textile.isInitialized(repoPath);
<span class="hljs-keyword">if</span> (!initialized) {
<span class="hljs-keyword">const</span> phrase = <span class="hljs-keyword">await</span> Textile.initializeCreatingNewWalletAndAccount(repoPath, <span class="hljs-literal">true</span>, <span class="hljs-literal">true</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"recovery phrase: "</span>, phrase);
}
Textile.launch(repoPath, <span class="hljs-literal">true</span>);
<span class="hljs-keyword">const</span> version = <span class="hljs-keyword">await</span> Textile.version();
<span class="hljs-keyword">this</span>.setState({version});
}
nodeOnline = <span class="hljs-function"><span class="hljs-params">()</span> =></span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"node online"</span>)
}
render() {
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag"><></span>
<span class="hljs-tag"><<span class="hljs-name">StatusBar</span> <span class="hljs-attr">barStyle</span>=<span class="hljs-string">"dark-content"</span> /></span>
<span class="hljs-tag"><<span class="hljs-name">SafeAreaView</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{flex:</span> <span class="hljs-attr">1</span>, <span class="hljs-attr">alignItems:</span> "<span class="hljs-attr">center</span>", <span class="hljs-attr">justifyContent:</span> "<span class="hljs-attr">center</span>"}}></span>
<span class="hljs-tag"><<span class="hljs-name">Text</span>></span>Textile version: {this.state.version}<span class="hljs-tag"></<span class="hljs-name">Text</span>></span>
<span class="hljs-tag"></<span class="hljs-name">SafeAreaView</span>></span>
<span class="hljs-tag"></></span></span>
);
}
}
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;</code></pre>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="globals.html"><em>Globals</em></a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_account_.html">"account"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_cafes_.html">"cafes"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_comments_.html">"comments"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_contacts_.html">"contacts"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_events_.html">"events"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_feed_.html">"feed"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_files_.html">"files"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_flags_.html">"flags"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_ignores_.html">"ignores"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_invites_.html">"invites"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_ipfs_.html">"ipfs"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_likes_.html">"likes"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_logs_.html">"logs"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_messages_.html">"messages"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_model_.html">"model"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_notifications_.html">"notifications"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_profile_.html">"profile"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_schemas_.html">"schemas"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_textile_.html">"textile"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_threads_.html">"threads"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_util_.html">"util"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_util_internal_.html">"util-<wbr>internal"</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
</nav>
</div>
</div>
</div>
<footer>
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
<li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
<script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script>
</body>
</html>