
When I try to learn something, I search around for the optimal approach. In the case of hooks I found two reasonable approaches and one approach that only makes sense in some use-cases. Below I've documented all of them.
I want to change the style of a text element when the user is clicking down on it. Because this is React Native for web, there are no CSS pseudo classes, so I need to manage all of the state myself. Because classes like active
, focus
, hover
, and visited
could be commonly used the API must be very self-contained.
... and I want people to like me, so I'm using hooks (the old implementation used render props).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta name="mobile-web-app-capable" content="yes" /> | |
<meta name="apple-touch-fullscreen" content="yes" /> | |
<meta name="apple-mobile-web-app-title" content="Expo" /> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<meta name="apple-mobile-web-app-status-bar-style" content="default" /> | |
<link | |
rel="apple-touch-icon" | |
sizes="180x180" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function uploadAudioAsync(uri) { | |
console.log("Uploading " + uri); | |
let apiUrl = 'http://YOUR_SERVER_HERE/upload'; | |
let uriParts = uri.split('.'); | |
let fileType = uriParts[uriParts.length - 1]; | |
let formData = new FormData(); | |
formData.append('file', { | |
uri, | |
name: `recording.${fileType}`, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
// import | |
import { MapView } from 'expo'; | |
export default BaseMap = ({ children, ...props }) => ( | |
<MapView | |
{...props} | |
> | |
<MapView.UrlTile | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GoogleAuthDemo $ exp build:ios -c | |
We've built a brand new CLI for Expo! | |
Expo CLI is a drop in replacement for exp. | |
Install: npm install -g expo-cli | |
Use: expo --help | |
Read more: https://blog.expo.io/expo-cli-2-0-released-a7a9c250e99c | |
[13:05:12] Making sure project is set up correctly... | |
[13:05:13] Your project looks good! | |
[13:05:13] Checking if current build exists... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import React Navigation | |
import { | |
createBottomTabNavigator, | |
createStackNavigator, | |
} from 'react-navigation'; | |
import tabBarIcon from './utils/tabBarIcon'; | |
// Import the screens | |
import FeedScreen from './screens/FeedScreen'; | |
import NewPostScreen from './screens/NewPostScreen'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Expo from 'expo'; | |
import * as ExpoPixi from 'expo-pixi'; | |
import React, { Component } from 'react'; | |
import { Image, StyleSheet, View } from 'react-native'; | |
export default class App extends Component { | |
state = { | |
strokeColor: Math.random() * 0xffffff, | |
strokeWidth: Math.random() * 30 + 10, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scaleLongestSideToSize = (mesh, size) => { | |
const { x: width, y: height, z: depth } = new THREE.Box3().setFromObject(mesh).getSize(); | |
const longest = Math.max(width, Math.max(height, depth)); | |
const scale = size / longest; | |
mesh.scale.set(scale, scale, scale); | |
} | |
export default scaleLongestSideToSize; |