Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGong2013 committed Nov 18, 2020
2 parents 8b0ef22 + f55397c commit 5d64272
Show file tree
Hide file tree
Showing 28 changed files with 2,241 additions and 172 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 0.4.0
# 0.4.1-pre.0

* Remove Page.Hidden event
* Custom FlutterActivity

## 0.4.0

* Support hybrid route stack.
* Automatically handle ios navigation bar hidden/show.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _Flutter **stable channel** 发布后 **一周内**适配发布对应的`g_farad

## Requirements

- Flutter 1.22.3
- Flutter 1.23.0-18.1.pre *flutter channel beta*
- iOS 10.0+ Xcode 12.0+ Swift 5.1+
- Android minSdkVersion 16 Kotlin 1.4.10+

Expand Down
9 changes: 5 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
//noinspection GradleDependency
classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,13 +26,13 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28

compileSdkVersion 29
// buildToolsVersion "29.0.3"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 23
}
lintOptions {
disable 'InvalidPackage'
Expand Down
11 changes: 4 additions & 7 deletions android/src/main/kotlin/com/yuxiaor/flutter/g_faraday/Faraday.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.yuxiaor.flutter.g_faraday.channels.CommonChannel
import com.yuxiaor.flutter.g_faraday.channels.FaradayNotice
import com.yuxiaor.flutter.g_faraday.channels.NetChannel
import com.yuxiaor.flutter.g_faraday.channels.NetHandler
import io.flutter.Log
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.plugin.common.MethodChannel
Expand Down Expand Up @@ -54,13 +55,9 @@ object Faraday {
// 这个navigator 必须先初始化 不能动
this.navigator = navigator
engine = FlutterEngine(context, null, automaticallyRegisterPlugins)
if (plugin != null) {
if (!engine.dartExecutor.isExecutingDart) {
engine.dartExecutor.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault())
}
return true
}
return false
Log.setLogLevel(android.util.Log.VERBOSE)
engine.dartExecutor.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault())
return pluginRef != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package com.yuxiaor.flutter.g_faraday
import android.content.Context
import android.content.Intent
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import android.os.PersistableBundle
//import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.XFlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import java.io.Serializable

/**
* Author: Edward
* Date: 2020-09-01
* Description:
*/
class FaradayActivity : FlutterActivity(), ResultProvider {
class FaradayActivity : XFlutterActivity(), ResultProvider {

private var seqId: Int? = null
private var resultListener: ((requestCode: Int, resultCode: Int, data: Intent?) -> Unit)? = null
Expand All @@ -21,16 +24,16 @@ class FaradayActivity : FlutterActivity(), ResultProvider {
private const val ARGS_KEY = "_flutter_args"
private const val ROUTE_KEY = "_flutter_route"

fun build(context: Context, routeName: String, params: HashMap<String, Any>? = null): Intent {
fun build(context: Context, routeName: String, params: Serializable? = null): Intent {
return Intent(context, FaradayActivity::class.java).apply {
putExtra(ROUTE_KEY, routeName)
putExtra(ARGS_KEY, params)
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun onAttachedToWindow() {
super.onAttachedToWindow()
createFlutterPage()
}

Expand All @@ -48,24 +51,21 @@ class FaradayActivity : FlutterActivity(), ResultProvider {
return Faraday.engine
}


override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
//ignore
}

override fun shouldDestroyEngineWithHost(): Boolean {
return false
}

override fun onResume() {
super.onResume()
seqId?.let { Faraday.plugin?.onPageShow(it) }
}

override fun onPause() {
super.onPause()
seqId?.let { Faraday.plugin?.onPageHidden(it) }
}

override fun onDestroy() {
super.onDestroy()
seqId?.let { Faraday.plugin?.onPageDealloc(it) }
super.onDestroy()
}

override fun addResultListener(resultListener: (requestCode: Int, resultCode: Int, data: Intent?) -> Unit) {
Expand All @@ -77,4 +77,5 @@ class FaradayActivity : FlutterActivity(), ResultProvider {
resultListener?.invoke(requestCode, resultCode, data)
resultListener = null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.flutter.embedding.engine.FlutterEngine
* Date: 2020-09-07
* Description:
*/
class FaradayFragment private constructor() : FlutterFragment(), ResultProvider {
class FaradayFragment : FlutterFragment(), ResultProvider {

private var seqId: Int? = null
private var resultListener: ((requestCode: Int, resultCode: Int, data: Intent?) -> Unit)? = null
Expand All @@ -33,16 +33,15 @@ class FaradayFragment private constructor() : FlutterFragment(), ResultProvider
}
}

override fun onAttach(context: Context) {
createFlutterPage()
super.onAttach(context)
}

override fun provideFlutterEngine(context: Context): FlutterEngine? {
return Faraday.engine
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
createFlutterPage()
}

internal fun createFlutterPage() {
val route = arguments?.getString(ROUTE_KEY)
require(route != null) { "route must not be null!" }
Expand All @@ -56,8 +55,6 @@ class FaradayFragment private constructor() : FlutterFragment(), ResultProvider
override fun onHiddenChanged(hidden: Boolean) {
if (!hidden) {
seqId?.let { Faraday.plugin?.onPageShow(it) }
} else {
seqId?.let { Faraday.plugin?.onPageHidden(it) }
}
super.onHiddenChanged(hidden)
}
Expand All @@ -67,24 +64,14 @@ class FaradayFragment private constructor() : FlutterFragment(), ResultProvider
seqId?.let { Faraday.plugin?.onPageShow(it) }
}

override fun onPause() {
super.onPause()
seqId?.let { Faraday.plugin?.onPageHidden(it) }
}

override fun onDetach() {
super.onDetach()
seqId?.let { Faraday.plugin?.onPageDealloc(it) }
}

override fun onDestroy() {
super.onDestroy()
seqId?.let { Faraday.plugin?.onPageDealloc(it) }
}

override fun shouldAttachEngineToActivity(): Boolean {
return true
}
// override fun shouldAttachEngineToActivity(): Boolean {
// return true
// }

override fun addResultListener(resultListener: (requestCode: Int, resultCode: Int, data: Intent?) -> Unit) {
this.resultListener = resultListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ import java.lang.ref.WeakReference
/** GFaradayPlugin */
class GFaradayPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

private val channel by lazy {
MethodChannel(Faraday.engine.dartExecutor, "g_faraday").apply {
setMethodCallHandler(this@GFaradayPlugin)
}
}
private lateinit var channel: MethodChannel

private var navigator: FaradayNavigator? = null
internal var binding: ActivityPluginBinding? = null

private var pageCount = 0;

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
when (call.method) {
"getPlatformVersion" -> result.success("Android ${android.os.Build.VERSION.RELEASE}")
"pushNativePage" -> {
val name = call.argument<String>("name")
require(name != null) { "page route name should not be null" }
Expand Down Expand Up @@ -74,6 +71,7 @@ class GFaradayPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
data["args"] = args
}
data["seq"] = seq ?: -1
pageCount++
channel.invoke("pageCreate", data) {
callback.invoke(it as Int)
}
Expand All @@ -83,25 +81,22 @@ class GFaradayPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
channel.invokeMethod("pageShow", seqId)
}

internal fun onPageHidden(seqId: Int) {
channel.invokeMethod("pageHidden", seqId)
}

internal fun onPageDealloc(seqId: Int) {
pageCount--
channel.invokeMethod("pageDealloc", seqId)
}


override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}


override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.binding = binding
}

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(binding.binaryMessenger, "g_faraday")
channel.setMethodCallHandler(this);
this.navigator = Faraday.navigator
Faraday.pluginRef = WeakReference(this)
}
Expand Down Expand Up @@ -131,4 +126,5 @@ class GFaradayPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
})
}

}
Loading

0 comments on commit 5d64272

Please sign in to comment.