Skip to content

Commit

Permalink
fixed webview scroll issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendraashutec committed Jan 7, 2020
1 parent 93e170f commit 5d98269
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"nativescript-imagecropper": "2.0.0",
"nativescript-imagepicker": "^6.2.0",
"nativescript-iqkeyboardmanager": "^1.5.1",
"nativescript-nested-scrollview": "^1.1.0",
"nativescript-plugin-firebase": "^10.0.0",
"nativescript-screenshot": "0.0.2",
"nativescript-social-share": "^1.5.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div *ngIf="show">
<ng-quill-tex (editorLoadFinished)="editorLoadFinished($event)" [styles]="{height: '50px'}" [modules]="quillConfig" (textChanged)="onTextChanged($event)"
<ng-quill-tex (editorLoadFinished)="editorLoadFinished($event)" [styles]="{height: '140px'}" [modules]="quillConfig" (textChanged)="onTextChanged($event)"
(fileUploaded)="fileUploaded($event)" [class.bottomToolbar]="applicationSettings?.quill_options?.custom_toolbar_position === 'bottom'" [customToolbarPosition]="applicationSettings?.quill_options?.custom_toolbar_position" [imageUrl]="quillImageUrl" [content]="editorContent" [isMobile]="true">
<span *ngIf="applicationSettings?.quill_options?.custom_toolbar_position === 'bottom'" class="ql-formats">
<div #bottomToolBar [innerHtml]='bottomBarOptions | safeHtml'></div>
Expand Down
1 change: 1 addition & 0 deletions projects/trivia/src/app/app.module.tns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ registerElement('PreviousNextView', () => require('nativescript-iqkeyboardmanage
// registerElement('CardView', () => CardView);
registerElement('CardView', () => require('nativescript-cardview').CardView);
registerElement('Fab', () => require('nativescript-floatingactionbutton').Fab);
registerElement("NestedScrollView", () => require("nativescript-nested-scrollview").NestedScrollView);

@NgModule({
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<GridLayout [class.dialogOpen]="isShowPreview" [isUserInteractionEnabled]="isWebViewLoaded" rows="*" columns="*"
*ngIf="!loaderBusy">
<StackLayout>
<ScrollView>
<NestedScrollView orientation="vertical">
<PreviousNextView row="0" col="0">
<GridLayout rows="*,auto,auto,auto,auto,auto" columns="*" (tap)="hideKeyboard()"
[formGroup]="questionForm" class="submit-question">
Expand Down Expand Up @@ -73,15 +73,15 @@
<Label *ngIf="!answers.valid && !answers.pristine" class="error-lbl error"
textWrap="true" text="All answers required !"></Label>
</StackLayout>
<StackLayout row="2" class="max-time-input" iosOverflowSafeArea="false">
<StackLayout row="2" class="max-time-input" iosOverflowSafeArea="false">
<GridLayout rows="*" columns="*">
<DropDown #timeDropdown itemsTextAlignment="center" row="0" [items]="playMaxTime"
selectedIndex="{{selectedMaxTimeIndex}}"
(selectedIndexChanged)="onchange($event)"></DropDown>
<Image (tap)="openTimeDropdown()" row="0" src="~/assets/images/dropdown_char.png"
class="tick-icon"></Image>
</GridLayout>
</StackLayout>
</StackLayout>
<StackLayout row="3" class="category-input" iosOverflowSafeArea="false">
<GridLayout rows="*,*" columns="*">
<GridLayout row="0" rows="*" columns="*">
Expand Down Expand Up @@ -152,7 +152,8 @@
</GridLayout>
</GridLayout>
</PreviousNextView>
</ScrollView>
</NestedScrollView>

</StackLayout>
<StackLayout *ngIf="!isWebViewLoaded">
<AbsoluteLayout (tap)="preventEventPropogation()" row="0" col="0">
Expand All @@ -164,9 +165,13 @@
</AbsoluteLayout>
</StackLayout>
<StackLayout height="0" #webViewParentStack>
<WebView height="140" width="100%" #webView id="questionWebView" (loaded)="webViewLoaded($event)">
</WebView>
<!-- <NestedScrollView height="0" #webViewParentStack> -->
<WebView height="215" width="100%" #webView id="questionWebView" (loaded)="webViewLoaded($event)" (touch)="onTouch($event)"> </WebView>
<!-- </NestedScrollView> -->


</StackLayout>

<StackLayout height="100%" class="dialog__wrapper">
<app-preview-question-dialog [question]="previewQuestion" [categoryDictionary]="categories">
</app-preview-question-dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { CONFIG } from "shared-library/environments/environment";
import * as Platform from "tns-core-modules/platform";

declare var IQKeyboardManager;
declare var android:any;

@Component({
selector: "app-question-add-update",
Expand Down Expand Up @@ -302,6 +303,7 @@ export class QuestionAddUpdateComponent extends QuestionAddUpdate
}
}
showEditor(type: string, id = -1) {

this.moveWebView(type, id);
if (type === "question") {
this.questionForm.patchValue({ isRichEditor: true });
Expand All @@ -328,11 +330,32 @@ export class QuestionAddUpdateComponent extends QuestionAddUpdate
: this.answerStack.filter((element, index) => index === id)[0]
.nativeElement;
this.currentWebViewParentId = id;

if (isAndroid) {

// for android this works as this method does not destroy the webview. do not change.
prevWebViewParent._removeViewFromNativeVisualTree(
this.webView.nativeElement
);
if(isAndroid){
this.webView.nativeElement.android.getSettings().setBuiltInZoomControls(false);
this.webView.nativeElement.android.setOnTouchListener(
new android.view.View.OnTouchListener({
onTouch: (view, motionEvent) => {
var action = motionEvent.getAction();
if (action === android.view.MotionEvent.ACTION_DOWN) {
view.getParent().requestDisallowInterceptTouchEvent(true);
}
if (action === android.view.MotionEvent.ACTION_UP) {
view.getParent().requestDisallowInterceptTouchEvent(false);
}
view.onTouchEvent(motionEvent);
return true;
}
})
);
}
this.webView.nativeElement.android.getSettings().setBuiltInZoomControls(false);
nextWebViewParent._addViewToNativeVisualTree(this.webView.nativeElement);
// need to wait for the load to be finished before emit the value.
setTimeout(() => {
Expand All @@ -349,6 +372,7 @@ export class QuestionAddUpdateComponent extends QuestionAddUpdate
}
}


public onchange(args: SelectedIndexChangedEventData) {
this.selectedMaxTimeIndex = args.newIndex;
this.questionForm.patchValue({
Expand Down Expand Up @@ -553,6 +577,7 @@ export class QuestionAddUpdateComponent extends QuestionAddUpdate
this.oWebViewInterface = this.setWebInterface(event.object);
// new webViewInterfaceModule.WebViewInterface(event.object, CONFIG.editorUrl);
}

if (this.oWebViewInterface && isIOS) {
event.object.initNativeView();
// need to wait for the load to be finished before emit the value.
Expand Down
5 changes: 2 additions & 3 deletions references.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" /> something

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/nativescript-iqkeyboardmanager/index.d.ts" />
/// <reference path="./node_modules/nativescript-iqkeyboardmanager/index.d.ts" />
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />

0 comments on commit 5d98269

Please sign in to comment.