Skip to content

Commit 329b052

Browse files
committed
Refactoring on Typescript (1)
1 parent c0322b3 commit 329b052

File tree

80 files changed

+3882
-3657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3882
-3657
lines changed

.eslintrc.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
module.exports = {
2+
root: true,
3+
extends: [
4+
"@react-native-community",
5+
"airbnb-typescript",
6+
"prettier",
7+
"prettier/@typescript-eslint",
8+
"prettier/react"
9+
],
210
parser: "babel-eslint",
3-
extends: "airbnb",
411
plugins: ["react", "react-native"],
512
env: {
613
jest: true,
@@ -11,7 +18,7 @@ module.exports = {
1118
"react/jsx-filename-extension": [
1219
"error",
1320
{
14-
extensions: [".js", ".jsx"]
21+
extensions: [".js", ".jsx", ".tsx", ".ts"]
1522
}
1623
],
1724
// for post defining style object in react-native

.prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
bracketSpacing: true,
3+
jsxBracketSameLine: false,
4+
singleQuote: false,
5+
trailingComma: "all",
6+
tabWidth: 2,
7+
semi: true,
8+
};

example/.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
22
root: true,
33
extends: '@react-native-community',
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
46
};

example/.flowconfig

-75
This file was deleted.

example/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ build/
2929
local.properties
3030
*.iml
3131

32+
# Visual Studio Code
33+
#
34+
.vscode/
35+
3236
# node.js
3337
#
3438
node_modules/

example/App.js renamed to example/App.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from "react";
22
import { View, Image, StatusBar, SafeAreaView } from "react-native";
3+
import AppleHeader from "react-native-apple-header";
34
import BottomSearchBar from "react-native-bottom-search-bar";
4-
import { AppleHeader } from "@freakycoder/react-native-header-view";
5-
import BouncyCheckbox from "react-native-bouncy-checkbox";
5+
// import BouncyCheckbox from "react-native-bouncy-checkbox";
6+
import BouncyCheckbox from "./lib/BouncyCheckbox"
67

78
const App = () => {
89
return (
@@ -29,12 +30,12 @@ const App = () => {
2930
textColor="#000"
3031
unfillColor="white"
3132
fontFamily="JosefinSans-Regular"
32-
iconComponent={
33-
<Image
34-
style={{ height: 10, width: 10 }}
35-
source={require("./assets/checkmark.png")}
36-
/>
37-
}
33+
// iconComponent={
34+
// <Image
35+
// style={{ height: 10, width: 10 }}
36+
// source={require("./assets/checkmark.png")}
37+
// />
38+
// }
3839
text="Custom Icon Example"
3940
/>
4041
<BouncyCheckbox
File renamed without changes.
File renamed without changes.

example/android/app/build.gradle

+22-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
21-
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
23+
* // https://reactnative.dev/docs/performance#enable-the-ram-format
2224
* bundleCommand: "ram-bundle",
2325
*
2426
* // whether to bundle JS and assets in debug mode
@@ -76,7 +78,6 @@ import com.android.build.OutputFile
7678
*/
7779

7880
project.ext.react = [
79-
entryFile: "index.js",
8081
enableHermes: false, // clean and rebuild if changing
8182
]
8283

@@ -156,12 +157,13 @@ android {
156157
}
157158
release {
158159
// Caution! In production, you need to generate your own keystore file.
159-
// see https://facebook.github.io/react-native/docs/signed-apk-android.
160+
// see https://reactnative.dev/docs/signed-apk-android.
160161
signingConfig signingConfigs.debug
161162
minifyEnabled enableProguardInReleaseBuilds
162163
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163164
}
164165
}
166+
165167
// applicationVariants are e.g. debug, release
166168
applicationVariants.all { variant ->
167169
variant.outputs.each { output ->
@@ -180,8 +182,24 @@ android {
180182

181183
dependencies {
182184
implementation fileTree(dir: "libs", include: ["*.jar"])
185+
//noinspection GradleDynamicVersion
183186
implementation "com.facebook.react:react-native:+" // From node_modules
184187

188+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
189+
190+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
191+
exclude group:'com.facebook.fbjni'
192+
}
193+
194+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
195+
exclude group:'com.facebook.flipper'
196+
exclude group:'com.squareup.okhttp3', module:'okhttp'
197+
}
198+
199+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
200+
exclude group:'com.facebook.flipper'
201+
}
202+
185203
if (enableHermes) {
186204
def hermesPath = "../../node_modules/hermes-engine/android/";
187205
debugImplementation files(hermesPath + "hermes-debug.aar")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5+
* directory of this source tree.
6+
*/
7+
package com.example;
8+
9+
import android.content.Context;
10+
import com.facebook.flipper.android.AndroidFlipperClient;
11+
import com.facebook.flipper.android.utils.FlipperUtils;
12+
import com.facebook.flipper.core.FlipperClient;
13+
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14+
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15+
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16+
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17+
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18+
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19+
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20+
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21+
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceManager;
23+
import com.facebook.react.bridge.ReactContext;
24+
import com.facebook.react.modules.network.NetworkingModule;
25+
import okhttp3.OkHttpClient;
26+
27+
public class ReactNativeFlipper {
28+
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
29+
if (FlipperUtils.shouldEnableFlipper(context)) {
30+
final FlipperClient client = AndroidFlipperClient.getInstance(context);
31+
32+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
33+
client.addPlugin(new ReactFlipperPlugin());
34+
client.addPlugin(new DatabasesFlipperPlugin(context));
35+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
36+
client.addPlugin(CrashReporterPlugin.getInstance());
37+
38+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39+
NetworkingModule.setCustomClientBuilder(
40+
new NetworkingModule.CustomClientBuilder() {
41+
@Override
42+
public void apply(OkHttpClient.Builder builder) {
43+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44+
}
45+
});
46+
client.addPlugin(networkFlipperPlugin);
47+
client.start();
48+
49+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
50+
// Hence we run if after all native modules have been initialized
51+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
52+
if (reactContext == null) {
53+
reactInstanceManager.addReactInstanceEventListener(
54+
new ReactInstanceManager.ReactInstanceEventListener() {
55+
@Override
56+
public void onReactContextInitialized(ReactContext reactContext) {
57+
reactInstanceManager.removeReactInstanceEventListener(this);
58+
reactContext.runOnNativeModulesQueueThread(
59+
new Runnable() {
60+
@Override
61+
public void run() {
62+
client.addPlugin(new FrescoFlipperPlugin());
63+
}
64+
});
65+
}
66+
});
67+
} else {
68+
client.addPlugin(new FrescoFlipperPlugin());
69+
}
70+
}
71+
}
72+
}

example/android/app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
16-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
17+
android:launchMode="singleTask"
1718
android:windowSoftInputMode="adjustResize">
1819
<intent-filter>
1920
<action android:name="android.intent.action.MAIN" />
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

example/android/app/src/main/java/com/example/MainApplication.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import com.facebook.react.PackageList;
66
import com.facebook.react.ReactApplication;
7+
import com.facebook.react.ReactInstanceManager;
78
import com.facebook.react.ReactNativeHost;
89
import com.facebook.react.ReactPackage;
910
import com.facebook.soloader.SoLoader;
@@ -43,23 +44,28 @@ public ReactNativeHost getReactNativeHost() {
4344
public void onCreate() {
4445
super.onCreate();
4546
SoLoader.init(this, /* native exopackage */ false);
46-
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
4748
}
4849

4950
/**
50-
* Loads Flipper in React Native templates.
51+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
52+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
5153
*
5254
* @param context
55+
* @param reactInstanceManager
5356
*/
54-
private static void initializeFlipper(Context context) {
57+
private static void initializeFlipper(
58+
Context context, ReactInstanceManager reactInstanceManager) {
5559
if (BuildConfig.DEBUG) {
5660
try {
5761
/*
5862
We use reflection here to pick up the class that initializes Flipper,
5963
since Flipper library is not available in release mode
6064
*/
61-
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
62-
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
65+
Class<?> aClass = Class.forName("com.example.ReactNativeFlipper");
66+
aClass
67+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
68+
.invoke(null, context, reactInstanceManager);
6369
} catch (ClassNotFoundException e) {
6470
e.printStackTrace();
6571
} catch (NoSuchMethodException e) {

example/android/build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
buildscript {
44
ext {
5-
buildToolsVersion = "28.0.3"
5+
buildToolsVersion = "29.0.2"
66
minSdkVersion = 16
7-
compileSdkVersion = 28
8-
targetSdkVersion = 28
7+
compileSdkVersion = 29
8+
targetSdkVersion = 29
99
}
1010
repositories {
1111
google()
1212
jcenter()
1313
}
1414
dependencies {
15-
classpath("com.android.tools.build:gradle:3.4.2")
16-
15+
classpath("com.android.tools.build:gradle:3.5.3")
1716
// NOTE: Do not place your application dependencies here; they belong
1817
// in the individual module build.gradle files
1918
}
@@ -33,6 +32,6 @@ allprojects {
3332

3433
google()
3534
jcenter()
36-
maven { url 'https://jitpack.io' }
35+
maven { url 'https://www.jitpack.io' }
3736
}
3837
}

example/android/gradle.properties

+7
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20+
# AndroidX package structure to make it clearer which packages are bundled with the
21+
# Android operating system, and which are packaged with your app's APK
22+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
2023
android.useAndroidX=true
24+
# Automatically convert third-party libraries to use AndroidX
2125
android.enableJetifier=true
26+
27+
# Version of flipper SDK to use with React Native
28+
FLIPPER_VERSION=0.37.0
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)