Skip to content

Commit fc20e91

Browse files
Altafk960Altaf Khan
andauthored
added new dark mode api documentation changes (SharePoint#9257)
* added new dark mode api documentation changes * added changes to make it more readable * removed unnecessary code to make it more readable * added the note * changed the version of the mentioned spfx package * updated the link for API --------- Co-authored-by: Altaf Khan <[email protected]>
1 parent 136bf89 commit fc20e91

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

docs/spfx/viva/design/designing-quick-view.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Currently dark themes are not supported for quick views on iOS and Android mobil
9393

9494
:::image type="content" source="../../../images/viva-design/img_quickview_ios_theme.jpg" alt-text="Screenshot that shows how a card viewed on mobile appears in light mode and dark mode.":::
9595

96-
We plan to introduce dark theme support in Quick View in Viva Connections Mobile for both iOS and Android in early Q4 of CY23. The API ([context.hostContext.theme](/javascript/api/sp-adaptive-card-extension-base/ihostcontext)) to get the theme in which Quick View is rendered of the Quick View will be available in SPFx 1.18.0 package.
96+
We plan to introduce dark theme support in Quick View in Viva Connections Mobile for both iOS and Android in early Q4 of CY23. ([context.sdks.microsoftTeams.teamsJs.app.getContext()](/javascript/api/sp-adaptive-card-extension-base/ipartialsdks?view=sp-typescript-latest)) to get the theme in which Quick View is rendered of the Quick View will be available in SPFx 1.18.1 package.
9797

9898
:::image type="content" source="../../../images/viva-design/img_quickview_new_ios_theme.png" alt-text="Screenshot that shows how a card quickview viewed on mobile will appear in light mode and dark mode.":::
9999

docs/spfx/viva/get-started/making-quickview-compatable-darkmode-mobile.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.localizationpriority: high
1111
1212
To adapt to the dark mode release in Viva Connections Mobile, which is scheduled for early Q4 of Calender Year 23, make sure that your card contents look compatible with both light and dark mode.
1313

14-
An API ([context.hostContext.theme](/javascript/api/sp-adaptive-card-extension-base/ihostcontext)) will be available in SPFx 1.18.0 package to get the information about the theme of the mobile app. This helps with using associated assets like images compliant to the theme. If you want to use two different sets of data while keeping the existing view style, follow these steps:
14+
An API ([context.sdks.microsoftTeams.teamsJs.app.getContext()](/javascript/api/sp-adaptive-card-extension-base/ipartialsdks?view=sp-typescript-latest)) will be available in SPFx 1.18.1 package to get the information about the theme of the mobile app. This helps with using associated assets like images compliant to the theme. If you want to use two different sets of data while keeping the existing view style, follow these steps:
1515

1616
- Let’s create a basic card with an image in Quick View. Locate and open the following file: **./src/adaptiveCardExtensions/helloWorld/quickView/template/QuickViewTemplate.json**.
1717
- Replace the contents of this file with the following JSON:
@@ -53,7 +53,47 @@ An API ([context.hostContext.theme](/javascript/api/sp-adaptive-card-extension-b
5353
}
5454
```
5555

56-
- Locate and open the following file: **./src/adaptiveCardExtensions/helloWorld/quickView/QuickView.ts**.
56+
- Locate and open the following file: **./src/adaptiveCardExtensions/helloWorld/helloWorldAdaptiveCardExtension.ts**.
57+
- Add a new state variable **theme** to the existing interface **IHelloWorldAdaptiveCardExtensionState**.Since the theme API returns a promise, we need to use a state variable to determine the current theme.
58+
59+
```typescript
60+
export interface IHelloWorldAdaptiveCardExtensionState {
61+
theme: string;
62+
}
63+
```
64+
65+
- For making the theme available to the card we are using API in the **onInit()** function.
66+
67+
```typescript
68+
69+
export default class helloWorldAdaptiveCardExtension extends BaseAdaptiveCardExtension<
70+
IHelloWorldAdaptiveCardExtensionProps,
71+
IHelloWorldAdaptiveCardExtensionState
72+
> {
73+
// ...
74+
75+
public onInit(): Promise<void> {
76+
this.state = {
77+
theme: "light"
78+
}
79+
80+
this.context.sdks?.microsoftTeams?.teamsJs.app.getContext().then((context) => {
81+
this.setState({
82+
theme: context.app.appInfo.theme
83+
});
84+
});
85+
86+
// registers the card view to be shown in a dashboard
87+
this.cardNavigator.register(CARD_VIEW_REGISTRY_ID, () => new CardView());
88+
// registers the quick view to open via QuickView action
89+
this.quickViewNavigator.register(QUICK_VIEW_REGISTRY_ID, () => new QuickView());
90+
91+
return Promise.resolve();
92+
}
93+
// ...
94+
}
95+
```
96+
5797
- Add a variable **imageUrl** to the existing interface **IQuickViewData** and add **imageUrl value** to **data()** function.
5898

5999
```typescript
@@ -98,7 +138,8 @@ export class QuickView extends BaseAdaptiveCardView<
98138

99139
```typescript
100140
public get data(): IQuickViewData {
101-
const isDarkTheme = (this.context.hostContext.theme === 'dark') ? true : false;
141+
// only two options are available for theme: 'dark' and 'default'
142+
const isDarkTheme = this.state.theme === 'dark' ? true : false;
102143
return {
103144
subTitle: strings.SubTitle,
104145
title: strings.Title,
@@ -114,4 +155,4 @@ public get data(): IQuickViewData {
114155
Similarly, we can customize our icons, images, and other elements of Quick View to support both light and dark theme.
115156

116157
> [!NOTE]
117-
> Please note that the value for ‘this.context.hostContext.theme’ is undefined for web and Teams app as they do not support dark theme and is only available for Viva Connections Mobile iOS and Android.
158+
> Please note that the value for ‘this.context.sdks.microsoftTeams.teamsJs.app.getContext()’ is undefined for web and Teams app as they do not support dark theme and is only available for Viva Connections Mobile iOS and Android.

0 commit comments

Comments
 (0)