-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[pointer_interceptor] Add platform interface #5499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 9 commits into
flutter:main
from
LouiseHsu:pointer_interceptor_platform_interface
Nov 30, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f267ed3
platform interface
LouiseHsu 206058a
pr comments
LouiseHsu 0fbd967
update read me links
LouiseHsu 29dd589
pubspec + authors file
LouiseHsu 38c41e2
fix unimplemented test
LouiseHsu c8c9051
add topics
LouiseHsu 4f8025e
add test for default behaviour
LouiseHsu 98aad1b
format
LouiseHsu 3054075
add topic
LouiseHsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/pointer_interceptor/pointer_interceptor_platform_interface/AUTHORS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Below is a list of people and organizations that have contributed | ||
# to the project. Names should be added to the list like so: | ||
# | ||
# Name/Organization <email address> | ||
|
||
Google Inc. |
3 changes: 3 additions & 0 deletions
3
packages/pointer_interceptor/pointer_interceptor_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.10.0 | ||
|
||
* Initial release from migration to federated architecture. |
25 changes: 25 additions & 0 deletions
25
packages/pointer_interceptor/pointer_interceptor_platform_interface/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright 2013 The Flutter Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 changes: 26 additions & 0 deletions
26
packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# pointer_interceptor_platform_interface | ||
|
||
A common platform interface for the [`pointer_interceptor`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `pointer_interceptor` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `pointer_interceptor`, extend | ||
[`PointerInterceptorPlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`PointerInterceptorPlatform` by calling | ||
`PointerInterceptorPlatform.instance = MyPointerInterceptorPlatform()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: https://pub.dev/packages/pointer_interceptor | ||
[2]: lib/src/pointer_interceptor_platform.dart |
5 changes: 5 additions & 0 deletions
5
...or/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// 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. | ||
|
||
export 'src/pointer_interceptor_platform.dart'; |
19 changes: 19 additions & 0 deletions
19
...terceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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/widgets.dart'; | ||
|
||
import 'pointer_interceptor_platform.dart'; | ||
|
||
/// A default no-op implementation of [PointerInterceptorPlatform]. | ||
class DefaultPointerInterceptor extends PointerInterceptorPlatform { | ||
@override | ||
Widget buildWidget({ | ||
required Widget child, | ||
bool debug = false, | ||
Key? key, | ||
}) { | ||
return child; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...erceptor/pointer_interceptor_platform_interface/lib/src/pointer_interceptor_platform.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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/widgets.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'default_pointer_interceptor.dart'; | ||
|
||
/// Platform-specific implementations should set this with their own | ||
/// platform-specific class that extends [PointerInterceptorPlatform] when | ||
/// they register themselves. | ||
abstract class PointerInterceptorPlatform extends PlatformInterface { | ||
/// Constructs a PointerInterceptorPlatform. | ||
PointerInterceptorPlatform() : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
static PointerInterceptorPlatform _instance = DefaultPointerInterceptor(); | ||
|
||
static set instance(PointerInterceptorPlatform? instance) { | ||
if (instance == null) { | ||
throw AssertionError( | ||
'Platform interfaces can only be set to a non-null instance'); | ||
} | ||
|
||
PlatformInterface.verify(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
/// The default instance of [PointerInterceptorPlatform] to use. | ||
/// | ||
/// Defaults to [DefaultPointerInterceptor], which does not do anything | ||
static PointerInterceptorPlatform get instance => _instance; | ||
|
||
/// Platform-specific implementations should override this function their own | ||
/// implementation of a pointer interceptor widget. | ||
Widget buildWidget({ | ||
LouiseHsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required Widget child, | ||
bool debug = false, | ||
Key? key, | ||
}) { | ||
throw UnimplementedError('buildWidget() has not been implemented.'); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: pointer_interceptor_platform_interface | ||
description: "A common platform interface for the pointer_interceptor plugin." | ||
repository: https://github.com/flutter/packages/tree/main/packages/pointer_interceptor/pointer_interceptor_platform_interface | ||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pointer_interceptor%22 | ||
|
||
version: 0.10.0 | ||
|
||
environment: | ||
sdk: '>=3.1.0 <4.0.0' | ||
flutter: '>=3.13.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
plugin_platform_interface: ^2.1.0 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
|
||
topics: | ||
- widgets | ||
- platform views | ||
- pointer-interceptor |
19 changes: 19 additions & 0 deletions
19
...rceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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/cupertino.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
test('Default implementation of PointerInterceptor does not do anything', () { | ||
final PointerInterceptorPlatform defaultPointerInterceptor = | ||
PointerInterceptorPlatform.instance; | ||
|
||
final Container testChild = Container(); | ||
expect(defaultPointerInterceptor.buildWidget(child: testChild), testChild); | ||
}); | ||
} |
27 changes: 27 additions & 0 deletions
27
...ceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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/cupertino.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
test( | ||
'Default implementation of PointerInterceptorPlatform should throw unimplemented error', | ||
() { | ||
final PointerInterceptorPlatform unimplementedPointerInterceptorPlatform = | ||
UnimplementedPointerInterceptorPlatform(); | ||
|
||
final Container testChild = Container(); | ||
expect( | ||
() => unimplementedPointerInterceptorPlatform.buildWidget( | ||
child: testChild), | ||
throwsUnimplementedError); | ||
Comment on lines
+15
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add another test file: |
||
}); | ||
} | ||
|
||
class UnimplementedPointerInterceptorPlatform | ||
extends PointerInterceptorPlatform {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably wanna put your name there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the format example.
The actual entries are below, and Google-employed contributors are covered by "Google".