Skip to content

Instantly share code, notes, and snippets.

View kaueDM's full-sized avatar

Kauê kaueDM

View GitHub Profile
$ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug...
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:react-native-fbsdk:compileLint
:react-native-fbsdk:copyReleaseLint UP-TO-DATE
:react-native-fbsdk:preBuild UP-TO-DATE
@kaueDM
kaueDM / build.gradle
Created February 23, 2017 23:34
build.gradle - sem usar 'force = true', o console retorna erro na tarefa :app:dexDebug - outDexFolder must be a folder
apply plugin: "com.android.application"
import com.android.build.OutputFile
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';
const options = {
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 1000
};
const myPosition = () => {
@kaueDM
kaueDM / Maps.js
Last active February 28, 2017 01:10
D:
// Componente do mapa --------------------------------
import React, { Component } from 'react';
import { connect } from 'react-redux';
import MapView from 'react-native-maps';
import { StyleSheet, View, Text, Dimensions } from 'react-native';
import { Spinner } from './common';
import { setLocation } from '../actions';
const { width, height } = Dimensions.get('window');
@kaueDM
kaueDM / wtf.js
Created April 26, 2017 00:11
wtf
//Instância do Firebase ('database' é o arquivo de configuração pra conectar)
const NewsInstance = firebase.initializeApp(database, 'NewsInstance');
const grabData = (dispatch, target) => {
return NewsInstance.database().ref(`/company-news/${target}`)
.on('value', snap => {
console.log('Data: ', JSON.stringify(snap.val()));
});
};
@kaueDM
kaueDM / example.js
Created June 23, 2017 22:37
Estrutura atual das minhas promises
const create = (userUID, customerObj) => {
return new Promise((resolve, reject) => {
const ref = database.ref('user_data').child(userUID).child('customers').push()
const key = ref.key;
ref.set(customerObj)
.then(() => {
resolve(key)
})
.catch(e => {
reject(e)
@kaueDM
kaueDM / get.js
Last active June 23, 2017 23:32
const getAll = (userUID) => {
return new Promise((resolve, reject) => {
const ref = database
.ref('user_data')
.child(userUID)
.child('customers')
.on('value', snap => {
(snap.val() ? resolve(snap.val()) : reject({'message': 'Empty Firebase node'}))
})
})
calcProgress() {
const percentage = ((100 / this.props.initial) * this.state.elapsed) / 100;
const current = this.props.initial - this.state.elapsed;
const elapsed = this.state.elapsed + 1000;
return this.setState({ percentage, current, elapsed })
}
playButton() {
let interval = setInterval(this.calcProgress, 1000);
@kaueDM
kaueDM / await.js
Created September 13, 2017 12:33
export const checkOpenTasks = (uid) => (dispatch) =>
new Promise((resolve, reject) => {
AsyncStorage.getItem(uid).then(item => {
if (item) {
const moments = Object.keys(JSON.parse(item));
const last = Math.max.apply(null, moments); //Último moment mesclado ao objeto
const { action, initial, elapsed } = JSON.parse(item)[last] //Ação realizada pelo último moment mesclado
const now = moment.utc().valueOf(); //Moment presente
const extra = (now - last) - ((now - last) % 1000); //Arredondamento - detalhes no README.md
resolve({ action, initial, elapsed, extra })
componentWillMount() {
this.props.getInitial(this.state.task);
this.props.checkOpenTasks(this.state.task)
.then((r) => {
if (r.action === 'play') {
this.setState({ elapsed: r.extra, status: 'running' });
let interval = setInterval(this.calcProgress, 1000);
this.setState({ interval });
//O interval só é definido depois pra que calcProgress não sobreescreva os dados do action creator
} else {