Skip to content

Instantly share code, notes, and snippets.

View krizzu's full-sized avatar

Krzysztof Borowy krizzu

View GitHub Profile
// All necessary imports
class AppAuthScreen extends Component {
async componentDidMount() {
const { navigation } = this.props;
const currentEmail = await AsyncStorage.getItem(
'@footballApp:currentEmail' // key used to save email during user singup
);
// @flow
import firebase from 'react-native-firebase';
export const DB = firebase.firestore();
export const USER_COLLECTION = 'users'; // name of collection in Firestore
export async function createUserDataBaseEntry(userId: string) {
// creating a new transaction
@krizzu
krizzu / MainActivity.java
Last active July 5, 2018 11:22
[Article] Standard Android code for RN
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "kotlin_app";
}
}
@krizzu
krizzu / MainActivity.kt
Created July 5, 2018 11:19
[Article] Kotlin version of standard RN android code
import com.facebook.react.ReactActivity
class MainActivity : ReactActivity() {
override fun getMainComponentName(): String? {
return "kotlin_app"
}
}
@krizzu
krizzu / build.gradle
Created July 5, 2018 10:16
[Article] App level build file
//...
apply plugin: "kotlin-android" // apply plugin
dependencies {
// ...
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // add dependency
}
// ...
@krizzu
krizzu / build.gradle
Created July 5, 2018 10:06
[Article] Top level build gradle
buildscript {
ext.kotlin_version = '1.2.31' // add version
// ...
dependencies {
// ...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Add kotlin dependency
}
}
// ...
@krizzu
krizzu / KotlinSyntaxCheatSheet.kt
Last active July 5, 2018 10:13
Small Cheatsheet for kotlin
/*
Variables
- Must be initialized with value
- Can be either immutable or mutable
- Can be null, but need to be declared with nullable type (more later)
- Various in Kotlin
- Numbers
- Byte
- Short
@krizzu
krizzu / React_pod_instructions.md
Last active July 11, 2019 18:14
How to use React as pod.

This gist will show you how to install and use React from Pods.

Podfile

target 'yourAppNameHere' do

  pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'BatchedBridge', # Required For React Native 0.45.0+
 'Core',
@krizzu
krizzu / AuthHoc.js
Created October 2, 2017 08:02
Example of HoC that check if user is authorised
import React, { Component } from 'react';
import firebase from './firebase'
// Child is our Wrapped component
export default (Child) => (
class AuthHoC extends Component {
state = {
isAuthenticated: false
}
@krizzu
krizzu / App.js
Created October 2, 2017 07:52
Example for simple authentication using RNFirebase
// ...
// Inside our Component's class
_authenticateUser = async () => {
const { firebase } = this.props; // Parent passes reference to Firebase through props
const { userPassword, userEmail } = this.state;
let userInfo = null;
try {
userInfo = await firebase.auth().signInWithEmailAndPassword(userEmail, userPassword)