mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Clipboard hasStrings method on iOS (flutter/engine#19859)
* Implement Clipboard hasStrings method on iOS * Test call to hasStrings * Formatting fixes * Move test to its own file * Alphabetical order * Update licenses * arguments nil instead of empty dictionary * Guarantee hasStrings will be true when tested * Formatting
This commit is contained in:
parent
be6640e520
commit
c611078344
@ -929,6 +929,7 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlay
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
|
||||
|
||||
@ -171,6 +171,7 @@ source_set("ios_test_flutter_mrc") {
|
||||
]
|
||||
sources = [
|
||||
"framework/Source/FlutterEnginePlatformViewTest.mm",
|
||||
"framework/Source/FlutterPlatformPluginTest.mm",
|
||||
"framework/Source/FlutterPlatformViewsTest.mm",
|
||||
"framework/Source/accessibility_bridge_test.mm",
|
||||
]
|
||||
|
||||
@ -88,6 +88,8 @@ using namespace flutter;
|
||||
} else if ([method isEqualToString:@"Clipboard.setData"]) {
|
||||
[self setClipboardData:args];
|
||||
result(nil);
|
||||
} else if ([method isEqualToString:@"Clipboard.hasStrings"]) {
|
||||
result([self clipboardHasStrings]);
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
@ -248,4 +250,16 @@ using namespace flutter;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary*)clipboardHasStrings {
|
||||
bool hasStrings = false;
|
||||
UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
||||
if (@available(iOS 10, *)) {
|
||||
hasStrings = pasteboard.hasStrings;
|
||||
} else {
|
||||
NSString* stringInPasteboard = pasteboard.string;
|
||||
hasStrings = stringInPasteboard != nil;
|
||||
}
|
||||
return @{@"value" : @(hasStrings)};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
// 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 <XCTest/XCTest.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
#import "third_party/ocmock/Source/OCMock/OCMock.h"
|
||||
|
||||
@interface FlutterPlatformPluginTest : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation FlutterPlatformPluginTest
|
||||
|
||||
- (void)testHasStrings {
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
|
||||
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
|
||||
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
|
||||
FlutterPlatformPlugin* plugin =
|
||||
[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()];
|
||||
|
||||
// Set some string to the pasteboard.
|
||||
__block bool calledSet = false;
|
||||
FlutterResult resultSet = ^(id result) {
|
||||
calledSet = true;
|
||||
};
|
||||
FlutterMethodCall* methodCallSet =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"Clipboard.setClipboardData"
|
||||
arguments:@{@"text" : @"some string"}];
|
||||
[plugin handleMethodCall:methodCallSet result:resultSet];
|
||||
XCTAssertEqual(calledSet, true);
|
||||
|
||||
// Call hasStrings and expect it to be true.
|
||||
__block bool called = false;
|
||||
__block bool value;
|
||||
FlutterResult result = ^(id result) {
|
||||
called = true;
|
||||
value = result[@"value"];
|
||||
};
|
||||
FlutterMethodCall* methodCall =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
|
||||
[plugin handleMethodCall:methodCall result:result];
|
||||
|
||||
XCTAssertEqual(called, true);
|
||||
XCTAssertEqual(value, true);
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
x
Reference in New Issue
Block a user