Skip to content

Commit 4af5cae

Browse files
committed
feat: ignore decodeRetVal on msgSendAsync()
1 parent ee8607a commit 4af5cae

File tree

9 files changed

+48
-39
lines changed

9 files changed

+48
-39
lines changed

dart_native/example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ EXTERNAL SOURCES:
2323

2424
SPEC CHECKSUMS:
2525
CocoaLumberjack: e8955b9d337ac307103b0a34fd141c32f27e53c5
26-
dart_native: ba4adc85a5cf6faafbfa7de2252397388d9480da
26+
dart_native: e10848b23206739fc16a2455f41847418a8ceb3d
2727
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
2828

2929
PODFILE CHECKSUM: f10e42e188a012076f9d5e111f499229a501832a

dart_native/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@
248248
inputPaths = (
249249
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
250250
"${PODS_ROOT}/../Flutter/Flutter.framework",
251+
"${PODS_ROOT}/../.symlinks/plugins/dart_native/ios/DartNative.framework",
251252
);
252253
name = "[CP] Embed Pods Frameworks";
253254
outputPaths = (
254255
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
256+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DartNative.framework",
255257
);
256258
runOnlyForDeploymentPostprocessing = 0;
257259
shellPath = /bin/sh;

dart_native/example/lib/ios/ios_main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class _IOSAppState extends State<IOSApp> {
3838
time = DateTime.now().millisecondsSinceEpoch;
3939

4040
for (var i = 0; i < 10000; i++) {
41-
String _ = stub.fooNSString(testString);
41+
// String _ = stub.fooNSString(testString);
42+
String a = await stub.fooNSStringAsync(testString);
43+
print(a);
4244
}
4345

4446
print("DartNative Cost: ${DateTime.now().millisecondsSinceEpoch - time}");

dart_native/example/lib/ios/runtimestub.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ class RuntimeStub extends NSObject {
249249
return NSString.fromPointer(result).raw;
250250
}
251251

252+
Future<String> fooNSStringAsync(String str) async {
253+
return performAsync(SEL('fooNSString:'),
254+
args: [str], onQueue: DispatchQueue.global())
255+
.then((value) {
256+
return NSString.fromPointer(value.pointer).raw;
257+
});
258+
}
259+
252260
String fooNSMutableString(String str) {
253261
NSMutableString _str = NSMutableString(str);
254262
Pointer<Void> result =

dart_native/example/lib/ios/unit_test.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,24 @@ testIOS(RuntimeStub stub, DelegateStub delegate) {
106106
set = stub.fooNSMutableSet(Set.from([1, 2.345, 'I\'m String', rect]));
107107
print('fooNSMutableSet to Set: $set');
108108

109-
stub.fooBlock((NSObject a) {
110-
print('hello block! ${a.description}');
111-
return a;
112-
});
109+
// stub.fooBlock((NSObject a) {
110+
// print('hello block! ${a.description}');
111+
// return a;
112+
// });
113113

114-
stub.fooStretBlock((CGAffineTransform a) {
115-
print('hello block stret! ${a.toString()}');
116-
return CGAffineTransform(12, 0, 12, 0, 12, 0);
117-
});
114+
// stub.fooStretBlock((CGAffineTransform a) {
115+
// print('hello block stret! ${a.toString()}');
116+
// return CGAffineTransform(12, 0, 12, 0, 12, 0);
117+
// });
118118

119-
stub.fooCStringBlock((CString a) {
120-
print('hello block cstring! $a');
121-
return CString('test return cstring');
122-
});
119+
// stub.fooCStringBlock((CString a) {
120+
// print('hello block cstring! $a');
121+
// return CString('test return cstring');
122+
// });
123123

124-
stub.fooCompletion(() {
125-
print('hello completion block!');
126-
});
124+
// stub.fooCompletion(() {
125+
// print('hello completion block!');
126+
// });
127127

128128
stub.fooDelegate(delegate);
129129

@@ -143,13 +143,13 @@ testIOS(RuntimeStub stub, DelegateStub delegate) {
143143
stub.fooWithOptions(TestOptions(TestOptionsOne | TestOptionsTwo));
144144
print('fooWithOptions result:$options');
145145

146-
Class('NSThread')
147-
.performAsync(SEL('currentThread'), onQueue: DispatchQueue.global())
148-
.then((currentThread) {
149-
NSObject description = currentThread.perform(SEL('description'));
150-
String threadResult = NSString.fromPointer(description.pointer).raw;
151-
print('currentThread: $threadResult');
152-
});
146+
// Class('NSThread')
147+
// .performAsync(SEL('currentThread'), onQueue: DispatchQueue.global())
148+
// .then((currentThread) {
149+
// NSObject description = currentThread.perform(SEL('description'));
150+
// String threadResult = NSString.fromPointer(description.pointer).raw;
151+
// print('currentThread: $threadResult');
152+
// });
153153

154154
NSNotificationCenter.defaultCenter.addObserver(
155155
delegate, delegate.handleNotification, 'SampleDartNotification', nil);
16.8 KB
Binary file not shown.

dart_native/ios/dart_native.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Write native code using Dart. This package liberates you from native code and lo
1515
s.source = { :path => '.' }
1616

1717
# Debug
18-
s.source_files = 'Classes/**/*', 'libffi/*.h', 'common/**/*'
19-
s.vendored_libraries = 'libffi/libffi.a'
18+
# s.source_files = 'Classes/**/*', 'libffi/*.h', 'common/**/*'
19+
# s.vendored_libraries = 'libffi/libffi.a'
2020

2121
# Release
22-
# s.source_files = 'Classes/DartNativePlugin.*'
23-
# s.vendored_frameworks = 'DartNative.framework'
22+
s.source_files = 'Classes/DartNativePlugin.*'
23+
s.vendored_frameworks = 'DartNative.framework'
2424

2525
s.public_header_files = 'Classes/DartNativePlugin.h'
2626
s.dependency 'Flutter'

dart_native/lib/src/ios/runtime/id.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ class id implements NSObjectProtocol {
108108
/// The message will consist of a [selector] and zero or more [args].
109109
///
110110
/// Returns a [Future] which completes to the received response, which may
111-
/// be null or nil. Return value will be converted to Dart types when
112-
/// [decodeRetVal] is `true`.
111+
/// be null or nil. Return value will be converted to Dart types.
113112
Future<dynamic> performAsync(SEL selector,
114-
{List args, DispatchQueue onQueue, bool decodeRetVal = true}) async {
115-
return msgSendAsync(this.pointer, selector,
116-
args: args, decodeRetVal: decodeRetVal, onQueue: onQueue);
113+
{List args, DispatchQueue onQueue}) async {
114+
return msgSendAsync(this.pointer, selector, args: args, onQueue: onQueue);
117115
}
118116

119117
/// Returns a Boolean value that indicates whether the receiver does not

dart_native/lib/src/ios/runtime/message.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ dynamic _msgSend(Pointer<Void> target, SEL selector,
105105

106106
Pointer<Void> callbackPtr = nullptr;
107107
if (callback != null) {
108+
// Return value is passed to block.
108109
Block block = Block(callback);
109110
callbackPtr = block.pointer;
110111
if (onQueue == null) {
@@ -146,14 +147,12 @@ dynamic msgSend(Pointer<Void> target, SEL selector,
146147
/// [onQueue] is `DispatchQueue.main` by default.
147148
///
148149
/// The message will consist of a [selector] and zero or more [args].
149-
/// Return value will be converted to Dart types when [decodeRetVal] is `true`.
150+
/// Return value will be converted to Dart types.
150151
Future<dynamic> msgSendAsync(Pointer<Void> target, SEL selector,
151-
{List args, bool decodeRetVal = true, DispatchQueue onQueue}) async {
152+
{List args, DispatchQueue onQueue}) async {
152153
final completer = Completer<dynamic>();
153-
_msgSend(target, selector,
154-
args: args,
155-
decodeRetVal: decodeRetVal,
156-
onQueue: onQueue, callback: (dynamic result) {
154+
_msgSend(target, selector, args: args, onQueue: onQueue,
155+
callback: (dynamic result) {
157156
completer.complete(result);
158157
});
159158
return completer.future;

0 commit comments

Comments
 (0)