Skip to content

Instantly share code, notes, and snippets.

View draftbitdocs's full-sized avatar

draftbitdocs

View GitHub Profile
import React, { useState, useEffect } from "react";
import { Dimensions, StyleSheet, Text, View } from "react-native";
import * as Location from "expo-location";
import MapView from "react-native-maps";
export const MyMapComponent = () => {
const [location, setLocation] = useState(null);
const [errorMsg, setErrorMsg] = useState(null);
// Request access for location permissions and store them
@draftbitdocs
draftbitdocs / XanoAuth-logout.js
Last active January 13, 2023 21:16
XanoAuth.logout()
function yourCustomFunctionName() {
XanoAuth.logout({ redirectTo: "SecretScreen" });
// or, to reset without redirect:
// logout();
}
@draftbitdocs
draftbitdocs / XanoAuth-login.js
Last active May 13, 2021 23:05
XanoAuth.login()
async function yourCustomFunctionName() {
try {
await XanoAuth.login({ email, password });
// Add your code here handling if successfull
// Ex: props.navigation.navigate("SecretScreen");
} catch(err) {
// Add your code here handling if failed.
// Ex: alert(err.message);
}
}
@draftbitdocs
draftbitdocs / isAuthenticated-snippet.js
Last active May 13, 2021 22:58
XanoAuth.isAuthenticated
React.useEffect(() => {
// No need to use this login screen, because it appears
// the user is already logged in.
if (XanoAuth.isAuthenticated) {
props.navigation.navigate("SecretScreen");
}
}, []);
@draftbitdocs
draftbitdocs / useProtectScreen-snippet.js
Last active May 13, 2021 22:49
useXanoAuth().useProtectScreen()
// If you have a screen named "Login":
XanoAuth.useProtectScreen({ redirectTo: "LoginScreen" });
@draftbitdocs
draftbitdocs / xano-auth-snippet.js
Last active March 24, 2022 22:08
Custom React hook to help with Xano authentication and authorization in Draftbit
import React from 'react';
import { useNavigation } from '@react-navigation/native';
import * as GlobalVariableContext from "./config/GlobalVariableContext";
/**
* Custom React Hook snippet for Xano (https://www.xano.com) authentication.
*
* Checkout Draftbit docs and community to learn more about using this snippet
* in Draftbit.
@draftbitdocs
draftbitdocs / variables.js
Last active May 13, 2021 20:01
Variables in Draftbit
import React from 'react';
import { Text, View, Button } from 'react-native';
import * as GlobalVariableContext from './config/GlobalVariableContext';
export const GlobalVariableComponent = () => {
const variables = GlobalVariableContext.useValues();
const setVariable = GlobalVariableContext.useSetValue();
return (
<View>
@draftbitdocs
draftbitdocs / components.js
Created April 22, 2021 18:27
GlobalVariableContext.useValues
import React from "react";
import { Text } from "react-native";
import * as GlobalVariableContext from "./config/GlobalVariableContext";
export const MyVariableDisplay = () => {
const variables = GlobalVariableContext.useValues();
return <Text> { variables.myGlobal } </Text>
};
@draftbitdocs
draftbitdocs / components.js
Last active April 29, 2021 19:39
GlobalVariableContext.useSetValue
import React from "react";
import { Button } from "react-native";
import * as GlobalVariableContext from "./config/GlobalVariableContext";
export const MyVariableSetter = () => {
const setGlobalVariable = GlobalVariableContext.useSetValue();
const myNewValue = { key: "mySettableGlobal", value: "new value" };
return (