Visitar URL original
[pigeon] added code generator for host->flutter calls for objc by gaaclarke · Pull Request #88 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ran formatter
  • Loading branch information
gaaclarke committed Feb 7, 2020
commit eeb8bfe195823f7b5574a4d185ce2ddb8f35cf75
12 changes: 8 additions & 4 deletions packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) {
indent.writeln('');
} else if (api.location == ApiLocation.flutter) {
indent.writeln('@interface $apiName : NSObject');
indent.writeln('- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;');
indent.writeln(
'- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;');
for (Method func in api.methods) {
final String returnType = _className(options.prefix, func.returnType);
final String argType = _className(options.prefix, func.argType);
Expand Down Expand Up @@ -224,11 +225,13 @@ void generateObjcSource(ObjcOptions options, Root root, StringSink sink) {
});
} else if (api.location == ApiLocation.flutter) {
indent.writeln('@interface $apiName ()');
indent.writeln('@property (nonatomic, strong) NSObject<FlutterBinaryMessenger>* binaryMessenger;');
indent.writeln(
'@property (nonatomic, strong) NSObject<FlutterBinaryMessenger>* binaryMessenger;');
indent.writeln('@end');
indent.addln('');
indent.writeln('@implementation $apiName');
indent.write('- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger>*)binaryMessenger ');
indent.write(
'- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger>*)binaryMessenger ');
indent.scoped('{', '}', () {
indent.writeln('self = [super init];');
indent.write('if (self) ');
Expand Down Expand Up @@ -257,7 +260,8 @@ void generateObjcSource(ObjcOptions options, Root root, StringSink sink) {
indent.write('[channel sendMessage:inputMap reply:^(id reply) ');
indent.scoped('{', '}];', () {
indent.writeln('NSDictionary* outputMap = reply;');
indent.writeln('$returnType * output = [$returnType fromMap:outputMap];');
indent.writeln(
'$returnType * output = [$returnType fromMap:outputMap];');
indent.writeln('completion(output, nil);');
});
});
Expand Down
5 changes: 4 additions & 1 deletion packages/pigeon/test/objc_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ void main() {
generateObjcHeader(ObjcOptions(header: 'foo.h'), root, sink);
final String code = sink.toString();
expect(code, contains('@interface Api : NSObject'));
expect(code, contains('initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;'));
expect(
code,
contains(
'initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;'));
expect(code, matches('void.*doSomething.*Input.*Output'));
});

Expand Down