Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7c363fd
dart side of implementation
bparrishMines May 11, 2022
2e55266
objc side of callback impl
bparrishMines May 12, 2022
4a12eaa
documentation and a test messenger
bparrishMines May 12, 2022
6bc048b
dart side update
bparrishMines May 16, 2022
4efa9a1
objc side
bparrishMines May 16, 2022
f9d54e2
formatting
bparrishMines May 16, 2022
2f73074
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 16, 2022
ddfde5c
handles
bparrishMines May 17, 2022
96c21ae
some fixes for PR comments
bparrishMines May 18, 2022
f2a3504
new instance manager
bparrishMines May 19, 2022
77da52f
bunch of work
bparrishMines May 19, 2022
e388090
instance manager tests
bparrishMines May 19, 2022
ac3a2de
fix foundation tests
bparrishMines May 19, 2022
696c25c
dart touchups
bparrishMines May 19, 2022
88816c9
finish dart standardization and support earlier versions
bparrishMines May 19, 2022
9d25ab1
fix dart instance manager
bparrishMines May 19, 2022
4d7ebc4
instance manager ish
bparrishMines May 19, 2022
81b201f
most tests passing
bparrishMines May 19, 2022
62581ba
instance manager tests
bparrishMines May 20, 2022
f0d2498
formatting and one last test
bparrishMines May 20, 2022
4bd6d2a
formatting
bparrishMines May 20, 2022
7974d56
naming
bparrishMines May 20, 2022
ad9b4e6
better comment
bparrishMines May 20, 2022
d8b720e
update comment with info about platform/flutter
bparrishMines May 23, 2022
3c98004
fix bug from instance manager identifier
bparrishMines May 24, 2022
368fb30
limits on identifiers
bparrishMines May 25, 2022
a6980c5
use removeReference name instead
bparrishMines May 25, 2022
179f109
maybe an even better name?
bparrishMines May 25, 2022
e966816
use init constructor
bparrishMines May 25, 2022
3897535
version bump
bparrishMines May 25, 2022
312825a
update name
bparrishMines May 25, 2022
36fa0a0
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 25, 2022
2b7a9af
undo changes to webview_flutter
bparrishMines May 25, 2022
86b193a
add api impls
bparrishMines May 25, 2022
61d5f8a
undo changes to create methods
bparrishMines May 25, 2022
29e8ad0
changes and stuff
bparrishMines May 25, 2022
2be09aa
some updates
bparrishMines May 26, 2022
e212aa4
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines May 26, 2022
ea0fe93
method names
bparrishMines May 26, 2022
9e47dda
more docs, yay
bparrishMines May 26, 2022
8076bed
spelling and docs
bparrishMines May 31, 2022
0fa7a14
pr comments
bparrishMines Jun 2, 2022
797d448
format and issue
bparrishMines Jun 2, 2022
ba8161a
Merge branch 'main' of github.com:flutter/plugins into callbacks
bparrishMines Jun 2, 2022
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
add api impls
  • Loading branch information
bparrishMines committed May 25, 2022
commit 86b193a8d7456fb4443bff2e9892a2486240205d
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import '../common/instance_manager.dart';
import '../common/web_kit.pigeon.dart';
import 'foundation.dart';

Iterable<NSKeyValueObservingOptionsEnumData>
_toNSKeyValueObservingOptionsEnumData(
Iterable<NSKeyValueObservingOptions> options,
) {
return options.map<NSKeyValueObservingOptionsEnumData>((
NSKeyValueObservingOptions option,
) {
late final NSKeyValueObservingOptionsEnum? value;
switch (option) {
case NSKeyValueObservingOptions.newValue:
value = NSKeyValueObservingOptionsEnum.newValue;
break;
case NSKeyValueObservingOptions.oldValue:
value = NSKeyValueObservingOptionsEnum.oldValue;
break;
case NSKeyValueObservingOptions.initialValue:
value = NSKeyValueObservingOptionsEnum.initialValue;
break;
case NSKeyValueObservingOptions.priorNotification:
value = NSKeyValueObservingOptionsEnum.priorNotification;
break;
}

return NSKeyValueObservingOptionsEnumData(value: value);
});
}

/// Handles initialization of Flutter APIs for the Foundation library.
// TODO(bparrishMines): Add NSObjectFlutterApiImpl once the callback methods
// are added.
class FoundationFlutterApis {
/// Constructs a [FoundationFlutterApis].
@visibleForTesting
FoundationFlutterApis({
BinaryMessenger? binaryMessenger,
// ignore: avoid_unused_constructor_parameters
InstanceManager? instanceManager,
}) : _binaryMessenger = binaryMessenger;

static FoundationFlutterApis _instance = FoundationFlutterApis();

/// Sets the global instance containing the Flutter Apis for the Foundation library.
@visibleForTesting
static set instance(FoundationFlutterApis instance) {
_instance = instance;
}

/// Global instance containing the Flutter Apis for the Foundation library.
static FoundationFlutterApis get instance {
return _instance;
}

// ignore: unused_field
final BinaryMessenger? _binaryMessenger;
bool _hasBeenSetUp = false;

/// Ensures all the Flutter APIs have been set up to receive calls from native code.
void ensureSetUp() {
if (!_hasBeenSetUp) {
_hasBeenSetUp = true;
}
}
}

/// Host api implementation for [NSObject].
@immutable
class NSObjectHostApiImpl extends NSObjectHostApi {
/// Constructs an [NSObjectHostApiImpl].
NSObjectHostApiImpl({
this.binaryMessenger,
InstanceManager? instanceManager,
}) : instanceManager = instanceManager ?? NSObject.globalInstanceManager,
super(binaryMessenger: binaryMessenger);

/// Sends binary data across the Flutter platform barrier.
///
/// If it is null, the default BinaryMessenger will be used which routes to
/// the host platform.
final BinaryMessenger? binaryMessenger;

/// Maintains instances stored to communicate with Objective-C objects.
final InstanceManager instanceManager;

/// Calls [addObserver] with the ids of the provided object instances.
Future<void> addObserverForInstances(
NSObject instance,
NSObject observer,
String keyPath,
Set<NSKeyValueObservingOptions> options,
) {
return addObserver(
instanceManager.getIdentifier(instance)!,
instanceManager.getIdentifier(observer)!,
keyPath,
_toNSKeyValueObservingOptionsEnumData(options).toList(),
);
}

/// Calls [removeObserver] with the ids of the provided object instances.
Future<void> removeObserverForInstances(
NSObject instance,
NSObject observer,
String keyPath,
) {
return removeObserver(
instanceManager.getIdentifier(instance)!,
instanceManager.getIdentifier(observer)!,
keyPath,
);
}

@override
int get hashCode {
return Object.hash(binaryMessenger, instanceManager);
}

@override
bool operator ==(Object other) {
return other is NSObjectHostApiImpl &&
binaryMessenger == other.binaryMessenger &&
instanceManager == other.instanceManager;
}
}