Skip to content

Commit 98b85da

Browse files
authored
[pointer_interceptor] Add platform interface (#5499)
Addresses flutter/flutter#30143 by adding an iOS implementation This PR is Part 1 of #5233
1 parent 83cb110 commit 98b85da

10 files changed

+199
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.10.0
2+
3+
* Initial release from migration to federated architecture.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2013 The Flutter Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# pointer_interceptor_platform_interface
2+
3+
A common platform interface for the [`pointer_interceptor`][1] plugin.
4+
5+
This interface allows platform-specific implementations of the `pointer_interceptor`
6+
plugin, as well as the plugin itself, to ensure they are supporting the
7+
same interface.
8+
9+
# Usage
10+
11+
To implement a new platform-specific implementation of `pointer_interceptor`, extend
12+
[`PointerInterceptorPlatform`][2] with an implementation that performs the
13+
platform-specific behavior, and when you register your plugin, set the default
14+
`PointerInterceptorPlatform` by calling
15+
`PointerInterceptorPlatform.instance = MyPointerInterceptorPlatform()`.
16+
17+
# Note on breaking changes
18+
19+
Strongly prefer non-breaking changes (such as adding a method to the interface)
20+
over breaking changes for this package.
21+
22+
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
23+
on why a less-clean interface is preferable to a breaking change.
24+
25+
[1]: https://pub.dev/packages/pointer_interceptor
26+
[2]: lib/src/pointer_interceptor_platform.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
export 'src/pointer_interceptor_platform.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/widgets.dart';
6+
7+
import 'pointer_interceptor_platform.dart';
8+
9+
/// A default no-op implementation of [PointerInterceptorPlatform].
10+
class DefaultPointerInterceptor extends PointerInterceptorPlatform {
11+
@override
12+
Widget buildWidget({
13+
required Widget child,
14+
bool debug = false,
15+
Key? key,
16+
}) {
17+
return child;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/widgets.dart';
6+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
7+
8+
import 'default_pointer_interceptor.dart';
9+
10+
/// Platform-specific implementations should set this with their own
11+
/// platform-specific class that extends [PointerInterceptorPlatform] when
12+
/// they register themselves.
13+
abstract class PointerInterceptorPlatform extends PlatformInterface {
14+
/// Constructs a PointerInterceptorPlatform.
15+
PointerInterceptorPlatform() : super(token: _token);
16+
17+
static final Object _token = Object();
18+
19+
static PointerInterceptorPlatform _instance = DefaultPointerInterceptor();
20+
21+
static set instance(PointerInterceptorPlatform? instance) {
22+
if (instance == null) {
23+
throw AssertionError(
24+
'Platform interfaces can only be set to a non-null instance');
25+
}
26+
27+
PlatformInterface.verify(instance, _token);
28+
_instance = instance;
29+
}
30+
31+
/// The default instance of [PointerInterceptorPlatform] to use.
32+
///
33+
/// Defaults to [DefaultPointerInterceptor], which does not do anything
34+
static PointerInterceptorPlatform get instance => _instance;
35+
36+
/// Platform-specific implementations should override this function their own
37+
/// implementation of a pointer interceptor widget.
38+
Widget buildWidget({
39+
required Widget child,
40+
bool debug = false,
41+
Key? key,
42+
}) {
43+
throw UnimplementedError('buildWidget() has not been implemented.');
44+
}
45+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: pointer_interceptor_platform_interface
2+
description: "A common platform interface for the pointer_interceptor plugin."
3+
repository: https://github.com/flutter/packages/tree/main/packages/pointer_interceptor/pointer_interceptor_platform_interface
4+
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pointer_interceptor%22
5+
6+
version: 0.10.0
7+
8+
environment:
9+
sdk: '>=3.1.0 <4.0.0'
10+
flutter: '>=3.13.0'
11+
12+
dependencies:
13+
flutter:
14+
sdk: flutter
15+
plugin_platform_interface: ^2.1.0
16+
17+
dev_dependencies:
18+
flutter_test:
19+
sdk: flutter
20+
21+
topics:
22+
- widgets
23+
- platform views
24+
- pointer-interceptor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/cupertino.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart';
8+
9+
void main() {
10+
TestWidgetsFlutterBinding.ensureInitialized();
11+
12+
test('Default implementation of PointerInterceptor does not do anything', () {
13+
final PointerInterceptorPlatform defaultPointerInterceptor =
14+
PointerInterceptorPlatform.instance;
15+
16+
final Container testChild = Container();
17+
expect(defaultPointerInterceptor.buildWidget(child: testChild), testChild);
18+
});
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/cupertino.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart';
8+
9+
void main() {
10+
TestWidgetsFlutterBinding.ensureInitialized();
11+
12+
test(
13+
'Default implementation of PointerInterceptorPlatform should throw unimplemented error',
14+
() {
15+
final PointerInterceptorPlatform unimplementedPointerInterceptorPlatform =
16+
UnimplementedPointerInterceptorPlatform();
17+
18+
final Container testChild = Container();
19+
expect(
20+
() => unimplementedPointerInterceptorPlatform.buildWidget(
21+
child: testChild),
22+
throwsUnimplementedError);
23+
});
24+
}
25+
26+
class UnimplementedPointerInterceptorPlatform
27+
extends PointerInterceptorPlatform {}

0 commit comments

Comments
 (0)