gekkou-react-native
v2.0.1
Published
The gekkou Wikia chat library, adapted for use with React Native Projects
Downloads
3
Maintainers
Readme
gekkou-react-native
A Wikia chat client for React Native. Fork of Gekkou.
Requirements
- NodeJS
- React Native (Tested with version 0.52.0, it should work with other versions too).
Note that this library doesn't have any native dependencies, this means you can use it with a CRNA or Expo project.
Installation
Add the package to your project:
Using Yarn: yarn add gekkou-react-native
Using NPM: npm install --save gekkou-react-native
Differences from core Gekkou
- Replaced the
request
module with the React Nativefetch
API. - The way you log in has changed a bit. In core Gekkou, you use
new Client('username', 'password').
Here you can log in two ways:
Logging in with a password
global.client = new Client({
username: 'Wikia username',
password: 'Wikia password'
});
Logging in with an access_token
This is specially useful if you, for example, ask for the user's credentials on a login screen and validate them there. This way, if you save the access token returned by https://services.wikia.com/auth/token
, you can use it to log in and avoid checking the credentials twice. This translates in less network requests, and a faster application.
global.client = new Client({
username: 'Wikia username',
token: 'access token'
});
Example: Ping Pong
import React from 'react';
import { Text, View } from 'react-native';
import { Client } from 'gekkou-react-native';
export default class GekkouExample extends React.Component {
componentDidMount() {
global.client = new Client({
username: 'Wikia username',
password: 'Wikia password'
});
client.on('ready', () => {
console.log('client ready!');
});
client.on('messageCreate', (msg) => {
console.log(`[${msg.author.username}]: ${msg.content}`);
});
client.connect('your-wiki-domain');
}
}
More examples can be found in the examples folder.