Skip to content

Instantly share code, notes, and snippets.

View ferrannp's full-sized avatar
🏋️‍♂️
At the gym

Ferran Negre ferrannp

🏋️‍♂️
At the gym
View GitHub Profile
import fetch from 'node-fetch';
import AdmZip from 'adm-zip';
import zlib from 'zlib';
import fs from 'fs';
import path from 'path';
const username = ''; // Add secret username
const password = ''; // Add secret password
const authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
// MainActivity.java
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}

React Native Folder Structure

Motivations

  • Sharing what has worked for me in different React Native projects
  • Reusing screens in different parts of your app
  • Easy to work separately in a feature
  • Add an extra level (nested folder) only when necessary
  • Don't overuse index.js for everything
// styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="android:windowBackground">@color/background</item>
</style>
// splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/darkBackground" />
<item
android:gravity="center"
android:bottom="72dp">
<bitmap
// styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="android:windowBackground">@color/background</item>
</style>
// RNSplashScreenModule.java
import android.app.Activity;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import javax.annotation.Nonnull;
// MainActivity.java
public void switchToReactView() {
if (mReactRootView != null && !mReactRootView.isAttachedToWindow()) {
mReactRootView.setAlpha(0f);
mReactRootView.animate()
.alpha(1f)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(350)
.setListener(new Animator.AnimatorListener() {
const Dropdown = (props) => (
<div className='dropdown'>
<button onClick={props.onToggle}>
Selected option: {props.data[props.optionSelected]}
</button>
<ul className={props.isOpen ? 'active':null}>
{
props.data.map((item, i) => {
return (
<li key={i} className={i === props.optionSelected ? 'selected':null}
static String currentLocale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainActivity.currentLocale = getResources().getConfiguration().locale.toString();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {