Skip to content

Commit b4f836a

Browse files
authoredJan 12, 2021
feat(framework): Create attachDirectionChange function (#2646)
1 parent 01cd6f9 commit b4f836a

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
 

‎packages/base/src/locale/applyDirection.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import RenderScheduler from "../RenderScheduler.js";
2+
import { fireDirectionChange } from "./directionChange.js";
23

34
/**
45
* Re-renders all RTL-aware UI5 Elements.
@@ -7,7 +8,9 @@ import RenderScheduler from "../RenderScheduler.js";
78
*
89
* @returns {Promise<void>}
910
*/
10-
const applyDirection = () => {
11+
const applyDirection = async () => {
12+
const listenersResults = fireDirectionChange();
13+
await Promise.all(listenersResults);
1114
RenderScheduler.reRenderAllUI5Elements({ rtlAware: true });
1215
return RenderScheduler.whenFinished();
1316
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import EventProvider from "../EventProvider.js";
2+
3+
const eventProvider = new EventProvider();
4+
const DIR_CHANGE = "directionChange";
5+
6+
/**
7+
* Attach a callback that will be executed whenever the application calls the "applyDirection" function
8+
* @public
9+
* @param listener
10+
*/
11+
const attachDirectionChange = listener => {
12+
eventProvider.attachEvent(DIR_CHANGE, listener);
13+
};
14+
15+
/**
16+
* Detach a callback that was passed with "attachDirectionChange"
17+
* @public
18+
* @param listener
19+
*/
20+
const detachDirectionChange = listener => {
21+
eventProvider.detachEvent(DIR_CHANGE, listener);
22+
};
23+
24+
const fireDirectionChange = () => {
25+
return eventProvider.fireEvent(DIR_CHANGE);
26+
};
27+
28+
export {
29+
attachDirectionChange,
30+
detachDirectionChange,
31+
fireDirectionChange,
32+
};

‎packages/main/bundle.esm.js

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
107107
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";
108108
import { getRegisteredNames as getIconNames } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js";
109109
import applyDirection from "@ui5/webcomponents-base/dist/locale/applyDirection.js";
110+
import { attachDirectionChange } from "@ui5/webcomponents-base/dist/locale/directionChange.js";
110111
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
111112

112113
const testAssets = {
@@ -125,6 +126,7 @@ const testAssets = {
125126
},
126127
getLocaleData,
127128
applyDirection,
129+
attachDirectionChange,
128130
ResizeHandler,
129131
addCustomCSS,
130132
attachThemeLoaded,

‎packages/main/test/pages/RTL.html

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
<ui5-date-picker></ui5-date-picker>
7979
<script>
8080

81+
setTimeout(function() {
82+
window['sap-ui-webcomponents-bundle'].attachDirectionChange(function() {
83+
console.log("Direction changed");
84+
});
85+
}, 1000);
86+
8187
// Utility function to change RTL and apply the changes
8288
function setDir(dir) {
8389
document.body.dir = dir;

0 commit comments

Comments
 (0)
Please sign in to comment.