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')}`;
// 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() {
// 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
static String currentLocale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainActivity.currentLocale = getResources().getConfiguration().locale.toString();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
const EnhanceDropdown = ComposedComponent => class extends Component {
constructor() {
super();
this.state = { isOpen: false };
this.onToggle = this.onToggle.bind(this);
this.handleDocumentClick = this.handleDocumentClick.bind(this);
this.onSelect = this.onSelect.bind(this);
}
componentDidMount() {
window.addEventListener('click', this.handleDocumentClick)