Skip to content

Commit 40a7684

Browse files
committed
Merge branch 'release/0.7.2'
2 parents 2fe1f4b + 857984d commit 40a7684

File tree

17 files changed

+71
-26
lines changed

17 files changed

+71
-26
lines changed

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ Dart finalizer is only supported above Flutter 3(Dart 2.17), but with DartNative
2626

2727
DartNative supports automatic type conversion so its bridging code is shorter & simpler than the Flutter channel.
2828

29-
A comparison of the task of "checking if an app needs to be installed" is shown below:
30-
31-
| | # of lines of bridging code | Coding complexity |
32-
| --- | --- | --- |
33-
| DartNative | Dart 1 + Native 1 | Autogenerated code returns BOOL directly |
34-
| Channel | Dart 15 + Native 30 | Needs to manually define return format, convert NSNumber to BOOL, determine channel & methodName |
35-
36-
3729
The design and vision of this package:
3830

3931
![](images/dartnative.png)
@@ -183,7 +175,7 @@ unitTest.addFinalizer(() { // register a finalizer callback.
183175
| List | NSArray | Array | List, ArrayList |
184176
| Map | NSDictionary | Dictionary | Map, HashMap |
185177
| Set | NSSet | Set | Set, HashSet |
186-
| Function | Block | Closure | Promise(TODO) |
178+
| Function | Block | Closure | Promise |
187179
| Pointer | void * | UnsafeMutableRawPointer | - |
188180
| NativeByte | NSData | Data | DirectByteBuffer |
189181
| NativeObject | NSObject | NSObject | Object |
@@ -310,11 +302,6 @@ NOTE: *If you use dart_native on macOS, you must use `use_frameworks!` in your P
310302
311303
## Documentation
312304
313-
### Readme
314-
315-
1. [dart_native README.md](/dart_native/README.md)
316-
2. [dart_native_gen README.md](/dart_native_gen/README.md)
317-
318305
### Further reading
319306
320307
- [告别 Flutter Channel,调用 Native API 仅需一行代码!](http://yulingtianxia.com/blog/2020/06/25/Codegen-for-DartNative/)

dart_native/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.2
2+
3+
* [Fix] Support Promise on Android.
4+
15
## 0.7.1
26

37
* [Fix] Leaks on iOS.

dart_native/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

dart_native/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/yangxiaoyu/Code/dart_native/README.md
-4.3 MB
Binary file not shown.
-4.11 MB
Binary file not shown.
-4.43 MB
Binary file not shown.
-4.27 MB
Binary file not shown.

dart_native/android/src/main/java/com/dartnative/dart_native/CallbackInvocationHandler.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.lang.reflect.InvocationHandler;
44
import java.lang.reflect.Method;
55
import java.util.HashMap;
6+
import java.util.concurrent.atomic.AtomicBoolean;
67

78
/**
89
* Created by huizzzhou on 2020/11/11.
@@ -19,8 +20,16 @@ public class CallbackInvocationHandler implements InvocationHandler {
1920
put("char", "java.lang.Character");
2021
}};
2122

23+
AtomicBoolean done = new AtomicBoolean(false);
24+
2225
@Override
2326
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
27+
boolean isDartFunctionHandler = proxy instanceof FunctionHandler;
28+
// For auto release memory, invoke only once.
29+
if (isDartFunctionHandler && done.getAndSet(true)) {
30+
throw new IllegalStateException("Invoke already submitted.");
31+
}
32+
args = (isDartFunctionHandler && args != null) ? (Object[]) args[0] : args;
2433
int argumentLength = args == null ? 0 : args.length;
2534
String[] paramsType = new String[argumentLength];
2635
for (int i = 0; i < argumentLength; i++) {
@@ -31,9 +40,12 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
3140
String returnType = method.getReturnType().getName();
3241
returnType = sBasicTypeConvert.get(returnType) == null ? returnType : sBasicTypeConvert.get(returnType);
3342
long dartObjectAddress = CallbackManager.getInstance().getRegisterDartAddr(proxy);
43+
if (isDartFunctionHandler) {
44+
CallbackManager.unRegisterCallback(proxy);
45+
}
3446

35-
return hookCallback(dartObjectAddress, funName, argumentLength, paramsType, args, returnType);
47+
return hookCallback(dartObjectAddress, funName, argumentLength, paramsType, args, returnType, isDartFunctionHandler);
3648
}
3749

38-
private native Object hookCallback(long dartObjectAddress, String funName, int argCount, String[] argTypes, Object[] args, String returnType);
50+
private native Object hookCallback(long dartObjectAddress, String funName, int argCount, String[] argTypes, Object[] args, String returnType, boolean isDartFunctionHandler);
3951
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.dartnative.dart_native;
2+
3+
public interface FunctionHandler {
4+
Object invoke(Object... arguments);
5+
}

0 commit comments

Comments
 (0)