Skip to content

Commit

Permalink
chore: remove device_info_plus and add quill_native_bridge to access …
Browse files Browse the repository at this point in the history
…platform specific APIs (#2194)

* chore(example): update the iOS platform project by Flutter

* chore: remove device_info_plus and create quill_native_bridge plugin

* chore: add quill_native_bridge from path in pubspec_overrides.yaml.disabled

* chore(scripts): add quill_native_bridge in the scripts/packages.dart

* ci: add quill_native_bridge in the GitHub workflows

* chore: use quill_native_briddge from pub.dev in flutter_quill
  • Loading branch information
EchoEllet authored Sep 11, 2024
1 parent fcbd2fc commit 8ae33a9
Show file tree
Hide file tree
Showing 25 changed files with 392 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: 📦 Install flutter_quill_test dependencies
run: flutter pub get -C flutter_quill_test

- name: 📦 Install quill_native_bridge dependencies
run: flutter pub get -C quill_native_bridge

- name: 🔍 Run Flutter analysis
run: flutter analyze

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ jobs:
- name: 📤 Publish flutter_quill_test
run: flutter pub publish --force
working-directory: ./flutter_quill_test/

- name: 📤 Publish quill_native_bridge
run: flutter pub publish --force
working-directory: ./quill_native_bridge/
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
12 changes: 2 additions & 10 deletions lib/src/common/utils/platform.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io' show Platform;

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart'
show TargetPlatform, defaultTargetPlatform, kDebugMode, kIsWeb;
import 'package:flutter/material.dart';
import 'package:quill_native_bridge/quill_native_bridge.dart';

// Android

Expand All @@ -26,15 +26,7 @@ Future<bool> isIOSSimulator() async {
return false;
}

final deviceInfo = DeviceInfoPlugin();

final osInfo = await deviceInfo.deviceInfo;

if (osInfo is IosDeviceInfo) {
final iosInfo = osInfo;
return !iosInfo.isPhysicalDevice;
}
return false;
return await QuillNativeBridge.isIOSSimulator();
}

// Mobile
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies:
# Plugins
url_launcher: ^6.2.4
flutter_keyboard_visibility: ^6.0.0
device_info_plus: ^10.0.1
quill_native_bridge: ^10.5.14

dev_dependencies:
flutter_lints: ^4.0.0
Expand Down
4 changes: 3 additions & 1 deletion pubspec_overrides.yaml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ dependency_overrides:
flutter_quill_test:
path: ./flutter_quill_test
dart_quill_delta:
path: ./dart_quill_delta
path: ./dart_quill_delta
quill_native_bridge:
path: ./quill_native_bridge
29 changes: 29 additions & 0 deletions quill_native_bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
30 changes: 30 additions & 0 deletions quill_native_bridge/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "5874a72aa4c779a02553007c47dacbefba2374dc"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
- platform: ios
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
3 changes: 3 additions & 0 deletions quill_native_bridge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 10.5.14

* TODO: This file will be updated soon by GitHub workflow.
21 changes: 21 additions & 0 deletions quill_native_bridge/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Flutter Quill Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions quill_native_bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 🪶 Quill Native Bridge

An internal plugin for [`flutter_quill`](https://pub.dev/packages/flutter_quill) package to access platform-specific APIs.

> [!NOTE]
> **Internal Use Only**: Exclusively for `flutter_quill`. Breaking changes may occur.
32 changes: 32 additions & 0 deletions quill_native_bridge/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include: package:flutter_lints/flutter.yaml

analyzer:
linter:
rules:
always_declare_return_types: true
always_put_required_named_parameters_first: true
annotate_overrides: true
avoid_empty_else: true
avoid_escaping_inner_quotes: true
avoid_print: true
avoid_types_on_closure_parameters: true
avoid_void_async: true
cascade_invocations: true
directives_ordering: true
omit_local_variable_types: true
prefer_const_constructors: true
prefer_const_constructors_in_immutables: true
prefer_const_declarations: true
prefer_final_fields: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_initializing_formals: true
prefer_int_literals: true
prefer_interpolation_to_compose_strings: true
prefer_relative_imports: true
prefer_single_quotes: true
sort_constructors_first: true
sort_unnamed_constructors_first: true
unnecessary_lambdas: true
unnecessary_parenthesis: true
unnecessary_string_interpolations: true
38 changes: 38 additions & 0 deletions quill_native_bridge/ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.idea/
.vagrant/
.sconsign.dblite
.svn/

.DS_Store
*.swp
profile

DerivedData/
build/
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m

.generated/

*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3

!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3

xcuserdata

*.moved-aside

*.pyc
*sync/
Icon?
.tags*

/Flutter/Generated.xcconfig
/Flutter/ephemeral/
/Flutter/flutter_export_environment.sh
Empty file.
23 changes: 23 additions & 0 deletions quill_native_bridge/ios/Classes/QuillNativeBridgePlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Flutter
import UIKit

public class QuillNativeBridgePlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "quill_native_bridge", binaryMessenger: registrar.messenger())
let instance = QuillNativeBridgePlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "isIOSSimulator":
#if targetEnvironment(simulator)
result(true)
#else
result(false)
#endif
default:
result(FlutterMethodNotImplemented)
}
}
}
29 changes: 29 additions & 0 deletions quill_native_bridge/ios/quill_native_bridge.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint quill_native_bridge.podspec` to validate before publishing.
#
Pod::Spec.new do |s|
s.name = 'quill_native_bridge'
s.version = '0.0.1'
s.summary = 'A plugin for flutter_quill'
s.description = <<-DESC
An internal plugin for flutter_quill package to access platform-specific APIs.
DESC
s.homepage = 'https://github.com/singerdmx/flutter-quill'
s.license = { :file => '../LICENSE' }
s.author = { 'Flutter Quill' => 'https://github.com/singerdmx/flutter-quill' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'

# If your plugin requires a privacy manifest, for example if it uses any
# required reason APIs, update the PrivacyInfo.xcprivacy file to describe your
# plugin's privacy impact, and then uncomment this line. For more information,
# see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
# s.resource_bundles = {'quill_native_bridge_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
end
14 changes: 14 additions & 0 deletions quill_native_bridge/lib/quill_native_bridge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
library;

import 'src/quill_native_bridge_platform_interface.dart';

class QuillNativeBridge {
QuillNativeBridge._();

/// Check if the app is running on [iOS Simulator](https://developer.apple.com/documentation/xcode/running-your-app-in-simulator-or-on-a-device).
///
/// This function should only be called when [defaultTargetPlatform]
/// is [TargetPlatform.iOS] and [kIsWeb] is `false`.
static Future<bool> isIOSSimulator() =>
QuillNativeBridgePlatform.instance.isIOSSimulator();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'quill_native_bridge_platform_interface.dart';

class MethodChannelQuillNativeBridge implements QuillNativeBridgePlatform {
@visibleForTesting
final methodChannel = const MethodChannel('quill_native_bridge');

@override
Future<bool> isIOSSimulator() async {
assert(() {
if (kIsWeb || defaultTargetPlatform != TargetPlatform.iOS) {
throw FlutterError(
'isIOSSimulator() method should be called only on iOS.',
);
}
return true;
}());
final isSimulator =
await methodChannel.invokeMethod<bool>('isIOSSimulator');
assert(() {
if (isSimulator == null) {
throw FlutterError(
'isSimulator should not be null.',
);
}
return true;
}());
return isSimulator ?? false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'quill_native_bridge_method_channel.dart';

abstract class QuillNativeBridgePlatform extends PlatformInterface {
/// Constructs a QuillNativeBridgePlatform.
QuillNativeBridgePlatform() : super(token: _token);

/// Avoid using `const` when creating the `Object` for `_token`
static final Object _token = Object();

static QuillNativeBridgePlatform _instance = MethodChannelQuillNativeBridge();

/// The default instance of [QuillNativeBridgePlatform] to use.
///
/// Defaults to [MethodChannelQuillNativeBridge].
static QuillNativeBridgePlatform get instance => _instance;

/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [QuillNativeBridgePlatform] when
/// they register themselves.
static set instance(QuillNativeBridgePlatform instance) {
PlatformInterface.verify(instance, _token);
_instance = instance;
}

/// Check if the app is running on [iOS Simulator](https://developer.apple.com/documentation/xcode/running-your-app-in-simulator-or-on-a-device).
Future<bool> isIOSSimulator() {
throw UnimplementedError('isIOSSimulator() has not been implemented.');
}
}
Loading

0 comments on commit 8ae33a9

Please sign in to comment.