Skip to content

Commit

Permalink
Merge pull request #1 from SummerRock/react_native_v1
Browse files Browse the repository at this point in the history
React native v1
  • Loading branch information
SummerRock authored Feb 21, 2024
2 parents 70d9f85 + 306a0db commit 5e0d2f2
Show file tree
Hide file tree
Showing 179 changed files with 7,047 additions and 163 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
.DS_Store
/build
/captures
/node_modules/
/local.properties
*.apk
*.apk
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
目前用Gradle 8.0 版本;需要使用 Java17
用了常用的第三方库,如 retrofit/eventbus等
利用自己业余时间开发出一款自己能满意的App,复盘、总结移动端开发知识,目前仍在开发中

React Native 打包命令:
# 注:如果你使用了 React Native Gradle Plugin,则其会自动执行以下命令,不需要手动执行
$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/.idea
.DS_Store
/build
/captures
/local.properties
*.apk
File renamed without changes.
55 changes: 43 additions & 12 deletions app/build.gradle → android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' // 引入 android gradle 插件
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply from: this.project.file('../config.gradle')
apply plugin: "com.facebook.react"

android { // 配置 android gradle plugin 需要的内容
compileSdkVersion this.project.ext.compileSdkVersion
Expand All @@ -11,7 +12,7 @@ android { // 配置 android gradle plugin 需要的内容
minSdkVersion this.project.ext.minSdkVersion
targetSdkVersion this.project.ext.targetSdkVersion
versionCode 1
versionName "1.0"
versionName "1.2"

javaCompileOptions {
annotationProcessorOptions {
Expand All @@ -22,6 +23,30 @@ android { // 配置 android gradle plugin 需要的内容
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
if (project.hasProperty("MYAPP_RELEASE_STORE_FILE")) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}

splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86_64'
universalApk false
}
}

aaptOptions {
cruncherEnabled = false
}

dataBinding {
enabled = true
}
Expand All @@ -36,7 +61,9 @@ android { // 配置 android gradle plugin 需要的内容
}

release {
minifyEnabled false
minifyEnabled true
signingConfig signingConfigs.release
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -51,9 +78,9 @@ dependencies { // 项目需要的依赖
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "androidx.appcompat:appcompat:$this.project.ext.appCompatVersion"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.4.+'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation "androidx.constraintlayout:constraintlayout:$this.project.ext.constraintlayout"
implementation "com.google.android.material:material:$this.project.ext.material"
implementation "androidx.vectordrawable:vectordrawable:$this.project.ext.vectordrawable"
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment:2.5.2'
Expand All @@ -69,19 +96,23 @@ dependencies { // 项目需要的依赖
implementation "org.greenrobot:eventbus:$this.project.ext.eventbus"
implementation "com.squareup.retrofit2:retrofit:$this.project.ext.retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$this.project.ext.retrofitVersion" // 如果需要使用 Gson 进行数据转换
implementation 'com.tencent:mmkv:1.2.10'
implementation 'androidx.preference:preference:1.2.0'
implementation "com.tencent:mmkv:$this.project.ext.mmkv"
implementation "androidx.preference:preference:$this.project.ext.preference"

implementation 'com.alibaba:arouter-api:1.5.1' // 请替换为最新版本号
kapt 'com.alibaba:arouter-compiler:1.5.1' // 请替换为最新版本号
implementation "com.alibaba:arouter-api:$this.project.ext.aRouter" // 请替换为最新版本号
kapt "com.alibaba:arouter-compiler:$this.project.ext.aRouter" // 请替换为最新版本号

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation "junit:junit:$this.project.ext.junit"
androidTestImplementation "androidx.test.ext:junit:$this.project.ext.ext_junit"
androidTestImplementation "androidx.test.espresso:espresso-core:$this.project.ext.espresso_core"
//依赖本地library
implementation project(path: ':commonmodule')
implementation project(path: ':monitor')
implementation project(path: ':react')

/** 上拉刷新、下拉加载 **/
implementation('com.scwang.smartrefresh:SmartRefreshLayout:1.1.0')

implementation "com.facebook.react:react-android"
implementation "com.facebook.react:hermes-android"
}
15 changes: 15 additions & 0 deletions commonmodule/proguard-rules.pro → android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep public class com.alibaba.android.arouter.routes.**{*;}
-keep public class com.alibaba.android.arouter.facade.**{*;}
-keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;}

# If you use the byType method to obtain Service, add the following rules to protect the interface:
-keep interface * implements com.alibaba.android.arouter.facade.template.IProvider

# If single-type injection is used, that is, no interface is defined to implement IProvider, the following rules need to be added to protect the implementation
-keep class * implements com.alibaba.android.arouter.facade.template.IProvider

# proguard-rules.pro

#-dontwarn javax.lang.model.element.**

Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<application
android:name=".BaseApplication"
android:allowBackup="true"
android:networkSecurityConfig="@xml/network_config"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="28">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name=".setting.SettingsActivity"
android:exported="false"
Expand All @@ -26,9 +31,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.MainActivity"
android:exported="false" />
</application>

</manifest>
491 changes: 491 additions & 0 deletions android/app/src/main/assets/index.android.bundle

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
Expand All @@ -17,12 +19,35 @@
import com.example.monitor.AppLifecycleListener;
import com.example.myapplication.base.login.LoginManager;
import com.example.myapplication.main.MainActivityV2;
import com.example.react.module.NetworkModulePackage;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;

import java.util.List;

public class BaseApplication extends Application {
public class BaseApplication extends Application implements ReactApplication {

private static BaseApplication instance;
private AppLifecycleListener appLifecycleListener;

private final ReactNativeHost mReactNativeHost = new DefaultReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here
packages.add(new NetworkModulePackage());
return packages;
}
};

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -42,10 +67,12 @@ public void onCreate() {
addLifeCycleMonitor();
setupCrashHandler();
LoginManager.Companion.getInstance().init();
SoLoader.init(this, false);
}

/**
* 在 onCreate() 方法之前调用
*
* @param base The new base context for this wrapper.
*/
@Override
Expand Down Expand Up @@ -96,4 +123,10 @@ private void restartToFirstActivity() {
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pendingIntent);
System.exit(2);
}

@NonNull
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.common.mainModule.ToastUtils;
import com.example.myapplication.BaseApplication;
import com.example.myapplication.base.model.NetworkModel;
import com.example.myapplication.base.net.RetrofitManager;
import com.common.net.RetrofitManager;

import org.greenrobot.eventbus.EventBus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.example.myapplication.R
import com.example.myapplication.base.login.model.LoginVo
import com.example.myapplication.base.model.EmptyVo
import com.example.myapplication.base.model.NetworkModel
import com.example.myapplication.base.net.RetrofitManager
import com.common.net.RetrofitManager
import org.greenrobot.eventbus.EventBus
import retrofit2.Call
import retrofit2.Callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityMainV2Binding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.myapplication.main.ui.dashboard;

public class CounterIntent {
public static class Increment extends CounterIntent {
}

public static class Decrement extends CounterIntent {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ public class DashboardFragment extends Fragment {

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
DashboardViewModel dashboardViewModel =
new ViewModelProvider(this).get(DashboardViewModel.class);
DashboardViewModel viewModel = new ViewModelProvider(this).get(DashboardViewModel.class);

binding = FragmentDashboardBinding.inflate(inflater, container, false);
View root = binding.getRoot();

final TextView textView = binding.textDashboard;
dashboardViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
viewModel.getCounterModelLiveData().observe(getViewLifecycleOwner(), counterModel -> {
textView.setText(String.valueOf(counterModel.getCount()));
});
binding.testIncrementBtn.setOnClickListener(v -> viewModel.processIntent(new CounterIntent.Increment()));
binding.testDecrementBtn.setOnClickListener(v -> viewModel.processIntent(new CounterIntent.Decrement()));
return root;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.myapplication.main.ui.dashboard;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.myapplication.main.ui.dashboard.model.CounterModel;

public class DashboardViewModel extends ViewModel {

private final MutableLiveData<CounterModel> counterModelLiveData = new MutableLiveData<>(new CounterModel(0));

public LiveData<CounterModel> getCounterModelLiveData() {
return counterModelLiveData;
}

public void processIntent(CounterIntent intent) {
CounterModel currentModel = counterModelLiveData.getValue();
CounterModel newModel = null;

if (intent instanceof CounterIntent.Increment) {
newModel = new CounterModel(currentModel.getCount() + 1);
} else if (intent instanceof CounterIntent.Decrement) {
newModel = new CounterModel(currentModel.getCount() - 1);
}

if (newModel != null) {
counterModelLiveData.setValue(newModel);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.myapplication.main.ui.dashboard.model;

public class CounterModel {
private final int count;

public CounterModel(int count) {
this.count = count;
}

public int getCount() {
return count;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import androidx.lifecycle.MutableLiveData;

import com.example.myapplication.base.model.NetworkModel;
import com.example.myapplication.base.net.RetrofitManager;
import com.common.net.RetrofitManager;
import com.example.myapplication.main.ui.home.model.HomeBannerVo;
import com.example.myapplication.main.ui.home.model.HomeModelVo;

Expand Down
Loading

0 comments on commit 5e0d2f2

Please sign in to comment.