Skip to content
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

Specify content density handling with Fiori Launchpad in more details #172

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
12 changes: 9 additions & 3 deletions docs/03_Get-Started/step-36-content-density-d935dbf.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In this step of our Walkthrough tutorial, we adjust the content density based on



**The content density is compact on desktop devices and cozy on touch-enabled devices**
**The default content density is cozy on touch devices (smartphones, tablets and computers with a touch screen) and compact on devices without a touch screen. Note that Fiori Launchpad sets cozy content density on phones and tablets as mandatory and may override it on other computers according to the application manifest and the user preference.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulasenka Is there a reason why this only is added for the JavaScript text but not to the TypeScript step?


![The graphic has an explanatory text.](images/UI5_Walkthrough_Step_36_f216b13.png "The content density is compact on desktop devices and cozy on touch-enabled
devices")
Expand All @@ -29,15 +29,21 @@ You can view and download all files at [Walkthrough - Step 36](https://ui5.sap.c
...

getContentDensityClass() {
return Device.support.touch ? "sapUiSizeCozy" : "sapUiSizeCompact";
// if the content density has already been set, don't override it
const classList = document.body.classList;
if (classList.contains("sapUiSizeCozy") || classList.contains("sapUiSizeCompact")) {
return "";
}
// if the application runs standalone, use cozy on touch devices
return Device.support.touch ? "sapUiSizeCozy" : "sapUiSizeCompact";
}
});
});
```

To prepare the content density feature we will also add a helper method `getContentDensityClass`. SAPUI5 controls can be displayed in multiple sizes, for example in a `compact` size that is optimized for desktop and non-touch devices, and in a `cozy` mode that is optimized for touch interaction. The controls look for a specific CSS class in the HTML structure of the application to adjust their size.

This helper method queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.
This helper method checks if the classes for the cozy or compact mode have been applied elsewhere already. If this is the case, the application will not apply it again. If not, it queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can view all files at [OpenUI5 TypeScript Walkthrough - Step 36: Content Den

To prepare the content density feature we add a helper method `getContentDensityClass` to the app component. SAPUI5 controls can be displayed in multiple sizes, for example in a `compact` size that is optimized for desktop and non-touch devices, and in a `cozy` mode that is optimized for touch interaction. The controls look for a specific CSS class in the HTML structure of the application to adjust their size.

This helper method queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.
This helper method checks if the classes for the cozy or compact mode have been applied elsewhere already. If this is the case, the application will not apply it again. If not, it queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.

```js
import UIComponent from "sap/ui/core/UIComponent";
Expand All @@ -47,6 +47,12 @@ export default class Component extends UIComponent {
...
};
getContentDensityClass(): string {
// if the content density has already been set, don't override it
const classList = document.body.classList;
if (classList.contains("sapUiSizeCozy") || classList.contains("sapUiSizeCompact")) {
return "";
}
// if the application runs standalone, use cozy on touch devices
return Device.support.touch ? "sapUiSizeCozy" : "sapUiSizeCompact";
}
};
Expand Down
20 changes: 9 additions & 11 deletions docs/04_Essentials/how-to-use-densities-for-controls-13e6f3b.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,19 @@ var btn = new Button({

## Using Density Classes in the SAP Fiori launchpad

The SAP Fiori launchpad \(FLP\) optionally reads the supported content densities from the app descriptor \(`manifest.json`\) and - if available - sets the appropriate content density class on the `<body>` tag. On devices with mouse and touch support, the FLP also allows the desired content density to be configured by the user. To avoid situations where an application and the FLP write different content density classes, we recommend using the following logic within all applications that are intended to be used inside the FLP:
The SAP Fiori launchpad \(FLP\) optionally reads the supported content densities from the app descriptor \(`manifest.json`\) and - if available - sets the appropriate content density class on the `<body>` tag. On desktop devices, the FLP also allows the desired content density to be configured by the user. To avoid situations where an application and the FLP write different content density classes, we recommend using the following logic within all applications that are intended to be used inside the FLP:

```js

getContentDensityClass : function() {
if (this._sContentDensityClass === undefined) {
// check whether FLP has already set the content density class; do nothing in this case
if (jQuery(document.body).hasClass("sapUiSizeCozy") || jQuery(document.body).hasClass("sapUiSizeCompact")) {
this._sContentDensityClass = "";
} else {
// Store "sapUiSizeCompact" or "sapUiSizeCozy" in this._sContentDensityClass, depending on which modes are supported by the app.
// E.g. the “cozy” class in case sap.ui.Device.support.touch is “true” and “compact” otherwise.
}
}
return this._sContentDensityClass;
// if the Fiori Launchpad has already set the content density class according to its logic, don't override it
const classList = document.body.classList;
if (classList.contains("sapUiSizeCozy") || classList.contains("sapUiSizeCompact")) {
return "";
}
// if the application runs standalone, use cozy on touch devices
return Device.support.touch ? "sapUiSizeCozy" : "sapUiSizeCompact";
}
}
```

Expand Down
Loading