9
9
debugModeProperty ,
10
10
displayZoomControlsProperty ,
11
11
domStorageProperty ,
12
+ isEnabledProperty ,
12
13
supportZoomProperty ,
13
14
traceMessageType ,
14
15
UnsupportedSDKError ,
@@ -128,7 +129,7 @@ function initializeWebViewClient(): void {
128
129
return super . shouldInterceptRequest ( view , request as android . webkit . WebResourceRequest ) ;
129
130
}
130
131
131
- let url : string ;
132
+ let url : string | void ;
132
133
if ( typeof request === "string" ) {
133
134
url = request ;
134
135
} else if ( typeof request === "object" ) {
@@ -525,7 +526,7 @@ export class WebViewExt extends WebViewExtBase {
525
526
526
527
const baseUrl = `file:///${ fs . knownFolders . currentApp ( ) . path } /` ;
527
528
this . writeTrace ( `WebViewExt<android>._loadData("${ src } ") -> baseUrl: "${ baseUrl } "` ) ;
528
- nativeView . loadDataWithBaseURL ( baseUrl , src , "text/html" , "utf-8" , null ) ;
529
+ nativeView . loadDataWithBaseURL ( baseUrl , src , "text/html" , "utf-8" , null ! ) ;
529
530
}
530
531
531
532
public get canGoBack ( ) : boolean {
@@ -637,14 +638,15 @@ export class WebViewExt extends WebViewExtBase {
637
638
}
638
639
639
640
const result = await new Promise < T > ( ( resolve , reject ) => {
640
- if ( ! this . nativeViewProtected ) {
641
+ const androidWebView = this . nativeViewProtected ;
642
+ if ( ! androidWebView ) {
641
643
this . writeTrace ( `WebViewExt<android>.executeJavaScript() -> no nativeView?` , traceMessageType . error ) ;
642
644
reject ( new Error ( "Native Android not initialized, cannot call executeJavaScript" ) ) ;
643
645
644
646
return ;
645
647
}
646
648
647
- this . nativeViewProtected . evaluateJavascript (
649
+ androidWebView . evaluateJavascript (
648
650
scriptCode ,
649
651
new android . webkit . ValueCallback ( {
650
652
onReceiveValue ( result : any ) {
@@ -662,19 +664,21 @@ export class WebViewExt extends WebViewExtBase {
662
664
}
663
665
664
666
public zoomIn ( ) {
665
- if ( ! this . nativeViewProtected ) {
667
+ const androidWebView = this . nativeViewProtected ;
668
+ if ( ! androidWebView ) {
666
669
return false ;
667
670
}
668
671
669
- return this . nativeViewProtected . zoomIn ( ) ;
672
+ return androidWebView . zoomIn ( ) ;
670
673
}
671
674
672
675
public zoomOut ( ) {
673
- if ( ! this . nativeViewProtected ) {
676
+ const androidWebView = this . nativeViewProtected ;
677
+ if ( ! androidWebView ) {
674
678
return false ;
675
679
}
676
680
677
- return this . nativeViewProtected . zoomOut ( ) ;
681
+ return androidWebView . zoomOut ( ) ;
678
682
}
679
683
680
684
public zoomBy ( zoomFactor : number ) {
@@ -704,46 +708,52 @@ export class WebViewExt extends WebViewExtBase {
704
708
}
705
709
706
710
[ builtInZoomControlsProperty . getDefault ] ( ) {
707
- if ( ! this . nativeViewProtected ) {
711
+ const androidWebView = this . nativeViewProtected ;
712
+ if ( ! androidWebView ) {
708
713
return false ;
709
714
}
710
715
711
- const settings = this . nativeViewProtected . getSettings ( ) ;
716
+ const settings = androidWebView . getSettings ( ) ;
712
717
713
718
return settings . getBuiltInZoomControls ( ) ;
714
719
}
715
720
716
721
[ builtInZoomControlsProperty . setNative ] ( enabled : boolean ) {
717
- if ( ! this . nativeViewProtected ) {
722
+ const androidWebView = this . nativeViewProtected ;
723
+ if ( ! androidWebView ) {
718
724
return ;
719
725
}
720
- const settings = this . nativeViewProtected . getSettings ( ) ;
726
+ const settings = androidWebView . getSettings ( ) ;
721
727
settings . setBuiltInZoomControls ( ! ! enabled ) ;
722
728
}
723
729
724
730
[ displayZoomControlsProperty . getDefault ] ( ) {
725
- if ( ! this . nativeViewProtected ) {
731
+ const androidWebView = this . nativeViewProtected ;
732
+ if ( ! androidWebView ) {
726
733
return false ;
727
734
}
728
- const settings = this . nativeViewProtected . getSettings ( ) ;
735
+
736
+ const settings = androidWebView . getSettings ( ) ;
729
737
730
738
return settings . getDisplayZoomControls ( ) ;
731
739
}
732
740
733
741
[ displayZoomControlsProperty . setNative ] ( enabled : boolean ) {
734
- if ( ! this . nativeViewProtected ) {
742
+ const androidWebView = this . nativeViewProtected ;
743
+ if ( ! androidWebView ) {
735
744
return ;
736
745
}
737
- const settings = this . nativeViewProtected . getSettings ( ) ;
746
+ const settings = androidWebView . getSettings ( ) ;
738
747
settings . setDisplayZoomControls ( ! ! enabled ) ;
739
748
}
740
749
741
- [ cacheModeProperty . getDefault ] ( ) : CacheMode {
742
- if ( ! this . nativeViewProtected ) {
750
+ [ cacheModeProperty . getDefault ] ( ) : CacheMode | null {
751
+ const androidWebView = this . nativeViewProtected ;
752
+ if ( ! androidWebView ) {
743
753
return null ;
744
754
}
745
755
746
- const settings = this . nativeViewProtected . getSettings ( ) ;
756
+ const settings = androidWebView . getSettings ( ) ;
747
757
const cacheModeInt = settings . getCacheMode ( ) ;
748
758
for ( const [ key , value ] of cacheModeMap ) {
749
759
if ( value === cacheModeInt ) {
@@ -755,11 +765,12 @@ export class WebViewExt extends WebViewExtBase {
755
765
}
756
766
757
767
[ cacheModeProperty . setNative ] ( cacheMode : CacheMode ) {
758
- if ( ! this . nativeViewProtected ) {
768
+ const androidWebView = this . nativeViewProtected ;
769
+ if ( ! androidWebView ) {
759
770
return ;
760
771
}
761
772
762
- const settings = this . nativeViewProtected . getSettings ( ) ;
773
+ const settings = androidWebView . getSettings ( ) ;
763
774
for ( const [ key , nativeValue ] of cacheModeMap ) {
764
775
if ( key === cacheMode ) {
765
776
settings . setCacheMode ( nativeValue ) ;
@@ -770,59 +781,84 @@ export class WebViewExt extends WebViewExtBase {
770
781
}
771
782
772
783
[ databaseStorageProperty . getDefault ] ( ) {
773
- if ( ! this . nativeViewProtected ) {
784
+ const androidWebView = this . nativeViewProtected ;
785
+ if ( ! androidWebView ) {
774
786
return false ;
775
787
}
776
788
777
- const settings = this . nativeViewProtected . getSettings ( ) ;
789
+ const settings = androidWebView . getSettings ( ) ;
778
790
779
791
return settings . getDatabaseEnabled ( ) ;
780
792
}
781
793
782
794
[ databaseStorageProperty . setNative ] ( enabled : boolean ) {
783
- if ( ! this . nativeViewProtected ) {
795
+ const androidWebView = this . nativeViewProtected ;
796
+ if ( ! androidWebView ) {
784
797
return ;
785
798
}
786
799
787
- const settings = this . nativeViewProtected . getSettings ( ) ;
800
+ const settings = androidWebView . getSettings ( ) ;
788
801
settings . setDatabaseEnabled ( ! ! enabled ) ;
789
802
}
790
803
791
804
[ domStorageProperty . getDefault ] ( ) {
792
- if ( ! this . nativeViewProtected ) {
805
+ const androidWebView = this . nativeViewProtected ;
806
+ if ( ! androidWebView ) {
793
807
return false ;
794
808
}
795
809
796
- const settings = this . nativeViewProtected . getSettings ( ) ;
810
+ const settings = androidWebView . getSettings ( ) ;
797
811
798
812
return settings . getDomStorageEnabled ( ) ;
799
813
}
800
814
801
815
[ domStorageProperty . setNative ] ( enabled : boolean ) {
802
- if ( ! this . nativeViewProtected ) {
816
+ const androidWebView = this . nativeViewProtected ;
817
+ if ( ! androidWebView ) {
803
818
return ;
804
819
}
805
820
806
- const settings = this . nativeViewProtected . getSettings ( ) ;
821
+ const settings = androidWebView . getSettings ( ) ;
807
822
settings . setDomStorageEnabled ( ! ! enabled ) ;
808
823
}
809
824
810
825
[ supportZoomProperty . getDefault ] ( ) {
811
- if ( ! this . nativeViewProtected ) {
826
+ const androidWebView = this . nativeViewProtected ;
827
+ if ( ! androidWebView ) {
812
828
return false ;
813
829
}
814
830
815
- const settings = this . nativeViewProtected . getSettings ( ) ;
831
+ const settings = androidWebView . getSettings ( ) ;
816
832
817
833
return settings . supportZoom ( ) ;
818
834
}
819
835
820
836
[ supportZoomProperty . setNative ] ( enabled : boolean ) {
821
- if ( ! this . nativeViewProtected ) {
837
+ const androidWebView = this . nativeViewProtected ;
838
+ if ( ! androidWebView ) {
822
839
return ;
823
840
}
824
841
825
- const settings = this . nativeViewProtected . getSettings ( ) ;
842
+ const settings = androidWebView . getSettings ( ) ;
826
843
settings . setSupportZoom ( ! ! enabled ) ;
827
844
}
845
+
846
+ [ isEnabledProperty . setNative ] ( enabled : boolean ) {
847
+ const androidWebView = this . nativeViewProtected ;
848
+ if ( ! androidWebView ) {
849
+ return ;
850
+ }
851
+
852
+ if ( enabled ) {
853
+ androidWebView . setOnTouchListener ( null ! ) ;
854
+ } else {
855
+ androidWebView . setOnTouchListener (
856
+ new android . view . View . OnTouchListener ( {
857
+ onTouch ( ) {
858
+ return true ;
859
+ } ,
860
+ } ) ,
861
+ ) ;
862
+ }
863
+ }
828
864
}
0 commit comments