Skip to content

Commit

Permalink
WIP #80 Added isTextInteractionEnabled to EpubScreen. Works on iOS. N…
Browse files Browse the repository at this point in the history
…ot implemented on Android yet.
  • Loading branch information
jmgeffroy committed Aug 11, 2023
1 parent d11e526 commit b57f195
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ViewerSettingsBloc
extends Bloc<ViewerSettingsEvent, ViewerSettingsState> {
ViewerSettingsBloc(EpubReaderState readerState)
: super(ViewerSettingsState(
ViewerSettings.defaultSettings(fontSize: readerState.fontSize))) {
ViewerSettings.defaultSettings(fontSize: readerState.fontSize, isTextInteractionEnabled: readerState.isTextInteractionEnabled))) {
on<ScrollSnapShouldStopEvent>((event, emit) => emit(ViewerSettingsState(
state.viewerSettings.setScrollSnapShouldStop(event.shouldStop))));
on<IncrFontSizeEvent>((event, emit) =>
Expand Down
10 changes: 7 additions & 3 deletions components/navigator/lib/src/epub/model/epub_reader_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import 'package:mno_commons/utils/jsonable.dart';
class EpubReaderState implements JSONable {
final String? themeName;
final int fontSize;
final bool isTextInteractionEnabled;

EpubReaderState(this.themeName, this.fontSize);
EpubReaderState(this.themeName, this.fontSize, this.isTextInteractionEnabled);

factory EpubReaderState.fromJson(Map<String, dynamic> json) =>
EpubReaderState(
json["themeName"] as String?, json["fontSize"] as int? ?? 100);
json["themeName"] as String?,
json["fontSize"] as int? ?? 100,
json["isTextInteractionEnabled"] as bool? ?? true);

@override
Map<String, dynamic> toJson() => {
if (themeName != null) 'themeName': themeName!,
'fontSize': fontSize,
'isTextInteractionEnabled': isTextInteractionEnabled
};

@override
String toString() =>
'EpubReaderState{themeName: $themeName, fontSize: $fontSize}';
'EpubReaderState{themeName: $themeName, fontSize: $fontSize, isTextInteractionEnabled: $isTextInteractionEnabled}';
}
30 changes: 22 additions & 8 deletions components/navigator/lib/src/epub/settings/viewer_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,51 @@ class ViewerSettings implements JSONable {
int fontSize;
final int columnGap;
bool scrollSnapShouldStop = true;
bool isTextInteractionEnabled = true;

// If true, column gap will not be part of JSON conversion
bool hasNoStyle = false;

ViewerSettings(this.syntheticSpreadMode, this.scrollMode, this.fontSize,
this.columnGap, this.scrollSnapShouldStop);
this.columnGap, this.scrollSnapShouldStop, this.isTextInteractionEnabled);

factory ViewerSettings.defaultSettings(
{int fontSize = 100, bool scrollSnapShouldStop = true}) =>
{int fontSize = 100,
bool scrollSnapShouldStop = true,
bool isTextInteractionEnabled = true}) =>
ViewerSettings(SyntheticSpreadMode.single, ScrollMode.auto, fontSize, 0,
scrollSnapShouldStop);
scrollSnapShouldStop, isTextInteractionEnabled);

ViewerSettings setScrollSnapShouldStop(bool shouldStop) => ViewerSettings(
this.syntheticSpreadMode,
this.scrollMode,
this.fontSize,
this.columnGap,
shouldStop);
shouldStop,
this.isTextInteractionEnabled);

ViewerSettings incrFontSize({int delta = 10}) {
int newFontSize = fontSize + delta;
newFontSize = newFontSize.clamp(minFontSize, maxFontSize);
return ViewerSettings(this.syntheticSpreadMode, this.scrollMode,
newFontSize, this.columnGap, this.scrollSnapShouldStop);
return ViewerSettings(
this.syntheticSpreadMode,
this.scrollMode,
newFontSize,
this.columnGap,
this.scrollSnapShouldStop,
this.isTextInteractionEnabled);
}

ViewerSettings decrFontSize({int delta = 10}) {
int newFontSize = fontSize - delta;
newFontSize = newFontSize.clamp(minFontSize, maxFontSize);
return ViewerSettings(this.syntheticSpreadMode, this.scrollMode,
newFontSize, this.columnGap, this.scrollSnapShouldStop);
return ViewerSettings(
this.syntheticSpreadMode,
this.scrollMode,
newFontSize,
this.columnGap,
this.scrollSnapShouldStop,
this.isTextInteractionEnabled);
}

bool get scrollViewDoc => scrollMode == ScrollMode.document;
Expand Down
41 changes: 21 additions & 20 deletions components/navigator/lib/src/epub/widget/webview_screen_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart' hide Decoration;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mno_webview/webview.dart';
// import 'package:mno_webview/webview.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:mno_navigator/epub.dart';
import 'package:mno_navigator/publication.dart';
import 'package:mno_navigator/src/epub/decoration.dart';
Expand All @@ -21,6 +22,7 @@ import 'package:mno_navigator/src/epub/model/decoration_style_annotation_mark.da
import 'package:mno_navigator/src/publication/model/annotation_type_and_idref_predicate.dart';
import 'package:mno_server/mno_server.dart';
import 'package:mno_shared/publication.dart';
import 'package:universal_io/io.dart';

@protected
class WebViewScreenState extends State<WebViewScreen> {
Expand Down Expand Up @@ -167,31 +169,28 @@ class WebViewScreenState extends State<WebViewScreen> {
? InAppWebView(
key: _webViewKey,
initialUrlRequest: URLRequest(
url: Uri.parse(
'${widget.address}/${link.href.removePrefix("/")}')),
initialOptions: InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
useShouldInterceptRequest: true,
safeBrowsingEnabled: false,
cacheMode: AndroidCacheMode.LOAD_NO_CACHE,
disabledActionModeMenuItems:
AndroidActionModeMenuItem.MENU_ITEM_SHARE |
AndroidActionModeMenuItem.MENU_ITEM_WEB_SEARCH |
AndroidActionModeMenuItem.MENU_ITEM_PROCESS_TEXT,
),
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
verticalScrollBarEnabled: false,
horizontalScrollBarEnabled: false,
),
url: WebUri('${widget.address}/${link.href.removePrefix("/")}')),
initialSettings: InAppWebViewSettings(
isInspectable: kDebugMode && Platform.isIOS,
isTextInteractionEnabled:
_viewerSettingsBloc.viewerSettings.isTextInteractionEnabled,
useHybridComposition: true,
useShouldInterceptRequest: true,
safeBrowsingEnabled: false,
cacheMode: CacheMode.LOAD_NO_CACHE,
disabledActionModeMenuItems: ActionModeMenuItem.MENU_ITEM_SHARE |
ActionModeMenuItem.MENU_ITEM_WEB_SEARCH |
ActionModeMenuItem.MENU_ITEM_PROCESS_TEXT,
useShouldOverrideUrlLoading: true,
verticalScrollBarEnabled: false,
horizontalScrollBarEnabled: false,
),
onConsoleMessage: (InAppWebViewController controller,
ConsoleMessage consoleMessage) {
Fimber.d(
"WebView[${consoleMessage.messageLevel}]: ${consoleMessage.message}");
},
androidShouldInterceptRequest: (InAppWebViewController controller,
shouldInterceptRequest: (InAppWebViewController controller,
WebResourceRequest request) async {
if (!_serverBloc.startHttpServer &&
request.url.toString().startsWith(_serverBloc.address)) {
Expand Down Expand Up @@ -249,6 +248,8 @@ class WebViewScreenState extends State<WebViewScreen> {
}
}

ViewerSettings get viewerSettings => _viewerSettingsBloc.viewerSettings;

Future _loadDecorations() async {
String activeId = "";
List<ReaderAnnotation> highlights =
Expand Down
Loading

0 comments on commit b57f195

Please sign in to comment.