Skip to content

fix (bottomsheet ios) correct resizing like on android version #277

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
merged 4 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo-vue/app.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = (env, params = {}) => {
exclude: /\.module\.scss$/,
use: [
{
loader: '@nativescript/webpack/helpers/css2json-loader',
loader: '@nativescript/webpack/dist/loaders/css2json-loader',
options: { useForImports: true }
},
{
Expand Down
4 changes: 2 additions & 2 deletions demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './bundle-config';
import * as app from '@nativescript/core/application';
import { Application } from '@nativescript/core';

import { installMixins, themer } from '@nativescript-community/ui-material-core';
import { install } from '@nativescript-community/ui-material-bottomsheet';
Expand All @@ -9,4 +9,4 @@ installMixins();
// themer.setPrimaryColor('red');
// themer.setPrimaryColorVariant('#3cff0000');

app.run({ moduleName: 'app-root' });
Application.run({ moduleName: 'app-root' });
2 changes: 1 addition & 1 deletion demo/app/examples/bottomnavigationbar-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BottomNavigationBar, TabPressedEventData, TabReselectedEventData, TabSelectedEventData } from '@nativescript-community/ui-material-bottomnavigationbar';
import { EventData } from '@nativescript/core/ui/core/view';
import { EventData } from '@nativescript/core';

export function onbottomNavigationBarLoaded(args: EventData): void {
const bottomNavigationBar = args.object as BottomNavigationBar;
Expand Down
2 changes: 1 addition & 1 deletion demo/app/examples/bottomsheetinner1-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventData, View } from '@nativescript/core/ui/core/view';
import { EventData, View } from '@nativescript/core';

// let closeCallback

Expand Down
3 changes: 1 addition & 2 deletions demo/app/examples/bottomsheetinner2-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EventData, View } from '@nativescript/core/ui/core/view';
import { ItemEventData } from '@nativescript/core/ui/list-view/list-view';
import { EventData, View, ItemEventData } from '@nativescript/core';

export function onTap(args: ItemEventData) {
const bindingContext = (args.object as View).bindingContext;
Expand Down
10 changes: 4 additions & 6 deletions demo/app/examples/bottomsheetinner2-fragment.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<StackLayout
xmlns:lv="nativescript-ui-listview"
xmlns:mdcr="@nativescript-community/ui-material-ripple"
>
<ListView id="listview" height="200" items="{{ dataItems }}" itemTap="onTap" class="list-group" backgroundColor="transparent">
<StackLayout xmlns:lv="nativescript-ui-listview" xmlns:mdcr="@nativescript-community/ui-material-ripple">
<Label text="Please select a value" backgroundColor="lightgrey" class="p-10"></Label>
<ListView id="listview" height="200" items="{{ dataItems }}" itemTap="onTap" class="list-group" backgroundColor="grey">
<ListView.itemTemplate>
<mdcr:Ripple class="list-group-item item-with-border">
<Label text="{{ title }}" textWrap="true" class="title"/>
</mdcr:Ripple>
</ListView.itemTemplate>
</ListView>
</StackLayout>
</StackLayout>
1 change: 1 addition & 0 deletions demo/app/examples/bottomsheetinner4-fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<WebView id="webview" height="300" src="https://github.com/nativescript-community/ui-material-components/blob/master/packages/bottomsheet/README.md" backgroundColor="red" padding="0" margin="0"></WebView>
2 changes: 1 addition & 1 deletion demo/app/examples/bottomsheets-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { View } from '@nativescript/core/ui/core/view';
import { View } from '@nativescript/core';

export function onViewTestLayoutChanged(args) {
const view: View = <View>args.object;
Expand Down
21 changes: 17 additions & 4 deletions demo/app/examples/bottomsheets-fragment.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<StackLayout xmlns:mdb="@nativescript-community/ui-material-button">
<mdb:Button id="bottomsheet1" text="bottomsheet" tap="{{ onTap }}"/>
<mdb:Button id="bottomsheet2" text="bottomsheet listview" tap="{{ onTap }}"/>
<mdb:Button id="bottomsheet3" text="bottomsheet without drag to close" tap="{{ onTap }}"/>
<ScrollView>
<StackLayout>
<mdb:Button id="bottomsheet1none" text="bottomsheet buttons\nignoreSafeArea: none" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet1top" text="bottomsheet buttons\nignoreSafeArea: top (default)" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet1bottom" text="bottomsheet buttons\nignoreSafeArea: bottom" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet1both" text="bottomsheet buttons\nignoreSafeArea: both" tap="{{ onTap }}" textWrap="true"/>

<mdb:Button id="bottomsheet2" text="bottomsheet listview" tap="{{ onTap }}"/>
<mdb:Button id="bottomsheet3" text="bottomsheet without drag to close" tap="{{ onTap }}"/>

<mdb:Button id="bottomsheet4none" text="bottomsheet webview\nignoreSafeArea: none" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet4top" text="bottomsheet webview\nignoreSafeArea: top (default)" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet4bottom" text="bottomsheet webview\nignoreSafeArea: bottom" tap="{{ onTap }}" textWrap="true"/>
<mdb:Button id="bottomsheet4both" text="bottomsheet webview\nignoreSafeArea: both" tap="{{ onTap }}" textWrap="true"/>
</StackLayout>
</ScrollView>

<StackLayout backgroundColor="red" xmlns:mdb="@nativescript-community/ui-material-button" layoutChanged="onViewTestLayoutChanged">
<mdb:Button id="test1" text="test1"/>
<mdb:Button id="test2" text="test2"/>
</StackLayout>
</StackLayout>
</StackLayout>
3 changes: 1 addition & 2 deletions demo/app/examples/dialogcustomview-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EventData, View } from '@nativescript/core/ui/core/view';
import { ItemEventData } from '@nativescript/core/ui/list-view/list-view';
import { EventData, View, ItemEventData } from '@nativescript/core';

export function onTap(args: ItemEventData) {
const bindingContext = (args.object as View).bindingContext;
Expand Down
109 changes: 99 additions & 10 deletions demo/app/examples/example-page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { NavigationButton } from '@nativescript/core/ui/action-bar/action-bar';
import { EventData, Frame, View } from '@nativescript/core/ui/frame/frame';
import { NavigationButton, EventData, Frame, View, ObservableArray, StackLayout, Label, Builder } from '@nativescript/core';
import { alert, AlertDialog, login, prompt } from '@nativescript-community/ui-material-dialogs';
import { ObservableArray } from '@nativescript/core/data/observable-array/observable-array';
const builder = require('@nativescript/core/ui/builder');

// importing adds the View augmentation
import { BottomSheetOptions } from '@nativescript-community/ui-material-bottomsheet';
import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout/stack-layout';
import { ActivityIndicator } from '@nativescript-community/ui-material-activityindicator';
import { Label } from '@nativescript/core/ui/label/label';
import { Button } from '@nativescript/core/ui/button/button';

function getObjectClass(obj) {
if (typeof obj !== 'object' || obj === null) return false;
Expand Down Expand Up @@ -82,9 +77,47 @@ class Model {
}).then(result => console.log('login result', result));
break;
}
case 'bottomsheet1': {
case 'bottomsheet1none': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner1-fragment',
ignoreBottomSafeArea: false,
ignoreTopSafeArea: false,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet1top': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner1-fragment',
ignoreBottomSafeArea: false,
ignoreTopSafeArea: true,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet1bottom': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner1-fragment',
ignoreBottomSafeArea: true,
ignoreTopSafeArea: false,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet1both': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner1-fragment',
ignoreBottomSafeArea: true,
ignoreTopSafeArea: true,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
Expand Down Expand Up @@ -118,6 +151,62 @@ class Model {
});
break;
}
case 'bottomsheet4none': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner4-fragment',
trackingScrollView: 'webview',
dismissOnDraggingDownSheet: false,
ignoreBottomSafeArea: false,
ignoreTopSafeArea: false,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet4top': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner4-fragment',
trackingScrollView: 'webview',
dismissOnDraggingDownSheet: false,
ignoreBottomSafeArea: false,
ignoreTopSafeArea: true,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet4bottom': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner4-fragment',
trackingScrollView: 'webview',
dismissOnDraggingDownSheet: false,
ignoreBottomSafeArea: true,
ignoreTopSafeArea: false,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'bottomsheet4both': {
obj.showBottomSheet({
view: 'examples/bottomsheetinner4-fragment',
trackingScrollView: 'webview',
dismissOnDraggingDownSheet: false,
ignoreBottomSafeArea: true,
ignoreTopSafeArea: true,
context: {},
closeCallback: objId => {
alert(`bottomsheet closed ${objId}`);
}
});
break;
}
case 'alertdialog':
const stack = new StackLayout();
stack.orientation = 'horizontal';
Expand Down Expand Up @@ -171,10 +260,10 @@ export function onNavigatingTo(args) {
// some-fragment.xml registered via bundle-config.ts, because it's postfixed with "fragment"
// so it already exist in bundle.js as module
console.log('loading xml', `./${exampleTitle}-fragment.xml`);
innerComponent = builder.parse(require(`./${exampleTitle}-fragment.xml`) as string, theModule);
innerComponent = Builder.parse(require(`./${exampleTitle}-fragment.xml`) as string, theModule);
} else {
console.log('loading xml', `${__dirname}/${exampleTitle}-fragment.xml`);
innerComponent = builder.load(`${__dirname}/${exampleTitle}-fragment.xml`, theModule);
innerComponent = Builder.load(`${__dirname}/${exampleTitle}-fragment.xml`, theModule);
}

container.addChild(innerComponent);
Expand Down
2 changes: 1 addition & 1 deletion demo/app/examples/progress-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, Page, PropertyChangeData } from '@nativescript/core/ui/page';
import { Observable, Page, PropertyChangeData } from '@nativescript/core';
import { Progress } from '@nativescript-community/ui-material-progress';

export function onNavigatingTo(args) {
Expand Down
3 changes: 1 addition & 2 deletions demo/app/examples/sliders-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Observable, PropertyChangeData } from '@nativescript/core/ui/core/view';
import { Page } from '@nativescript/core/ui/page';
import { Observable, PropertyChangeData, Page } from '@nativescript/core';
import { Slider } from '@nativescript-community/ui-material-slider';

export function onNavigatingTo(args) {
Expand Down
3 changes: 1 addition & 2 deletions demo/app/home/home-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Frame } from '@nativescript/core/ui/frame/frame';
import { ItemEventData } from '@nativescript/core/ui/list-view';
import { Frame, ItemEventData } from '@nativescript/core';
const examples = ['buttons', 'cardview', 'ripple', 'textfields', 'textviews', 'sliders', 'progress', 'activityindicators', 'dialogs', 'bottomsheets', 'mixins', 'snackbar', 'bottomnavigationbar'];

export class ViewModel {
Expand Down
6 changes: 3 additions & 3 deletions src/bottomsheet/bottomsheet-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class ViewWithBottomSheetBase extends View {
eventName: shownInBottomSheetEvent,
object: this,
context: this._bottomSheetContext,
closeCallback: this._closeBottomSheetCallback,
closeCallback: this._closeBottomSheetCallback
};

this.notify(args);
Expand Down Expand Up @@ -114,7 +114,7 @@ export abstract class ViewWithBottomSheetBase extends View {
eventName: showingInBottomSheetEvent,
object: this,
context: this._bottomSheetContext,
closeCallback: this._closeBottomSheetCallback,
closeCallback: this._closeBottomSheetCallback
};
this.notify(args);
}
Expand All @@ -138,7 +138,7 @@ export abstract class ViewWithBottomSheetBase extends View {
options.view instanceof View
? (options.view as ViewWithBottomSheetBase)
: (Builder.createViewFromEntry({
moduleName: options.view as string,
moduleName: options.view as string
}) as ViewWithBottomSheetBase);
view._showNativeBottomSheet(this, options);
return view;
Expand Down
44 changes: 36 additions & 8 deletions src/bottomsheet/bottomsheet.ios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IOSHelper, Page, Trace, Utils, View, fromObject } from '@nativescript/core';
import { Application, IOSHelper, Page, Screen, Trace, Utils, View, fromObject } from '@nativescript/core';
import { iOSNativeHelper } from '@nativescript/core/utils';
import { iosIgnoreSafeAreaProperty } from '@nativescript/core/ui/core/view/view-common';
import { applyMixins } from '@nativescript-community/ui-material-core';
import { BottomSheetOptions } from './bottomsheet';
import { ViewWithBottomSheetBase } from './bottomsheet-common';
Expand Down Expand Up @@ -92,11 +94,11 @@ function layoutView(controller: IUILayoutViewController, owner: View): void {
const marginLeft = owner.effectiveMarginLeft + position.left;
const marginRight = owner.effectiveMarginRight;
const top = marginTop + position.top;
const width = owner.getMeasuredWidth();
const width = Screen.mainScreen.widthPixels;
const height = owner.getMeasuredHeight();
View.layoutChild(null, owner, position.left, top, position.left + width + marginLeft + marginRight, position.top + height + marginBottom);
View.layoutChild(null, owner, marginLeft, top, width - marginLeft - marginRight, position.top + height + marginBottom);

const effectiveWidth = width + marginLeft + marginRight;
const effectiveWidth = width;
let effectiveHeight = height + top + marginBottom;
if (controller.ignoreTopSafeArea || controller.ignoreBottomSafeArea) {
const frame = CGRectMake(
Expand All @@ -113,14 +115,40 @@ function layoutView(controller: IUILayoutViewController, owner: View): void {

const adjustedPosition = startPos;

const orientation = UIDevice.currentDevice.orientation;
const isLandscape = Application.orientation() === 'landscape';

// there are still some issues in landscape Right but they seem to come from N

owner.iosIgnoreSafeArea = !isLandscape;
if (controller.ignoreTopSafeArea) {
const delta = safeAreaPosition.top - fullscreenPosition.top;
let key = 'top';
let oppositeKey = 'bottom';
if (orientation === UIDeviceOrientation.LandscapeLeft) {
key = 'left';
oppositeKey = 'right';
} else if (orientation === UIDeviceOrientation.LandscapeRight) {
key = 'right';
oppositeKey = 'left';
} else if (orientation === UIDeviceOrientation.PortraitUpsideDown) {
key = 'bottom';
oppositeKey = 'top';
}
const delta = safeAreaPosition[key] - fullscreenPosition[key];
effectiveHeight -= delta;
adjustedPosition.bottom -= delta;
adjustedPosition.top -= delta;
adjustedPosition[oppositeKey] -= delta;
adjustedPosition[key] -= delta;
}
if (controller.ignoreBottomSafeArea) {
const delta = fullscreenPosition.bottom - safeAreaPosition.bottom;
let key = 'bottom';
if (orientation === UIDeviceOrientation.LandscapeLeft) {
key = 'right';
} else if (orientation === UIDeviceOrientation.LandscapeRight) {
key = 'left';
} else if (orientation === UIDeviceOrientation.PortraitUpsideDown) {
key = 'top';
}
const delta = fullscreenPosition[key] - safeAreaPosition[key];
effectiveHeight -= delta;
}
owner.nativeViewProtected.frame = CGRectMake(
Expand Down