Skip to content

Commit

Permalink
[RNMobile] [Embed block] Fix content disappearing on Android when swi…
Browse files Browse the repository at this point in the history
…tching light/dark mode (#34207)

* Add dark/light mode value in sandbox key for Android

* Use usePreferredColorScheme hook

* Fetch color scheme in sandbox component directly

* Update react-native-editor changelog

Additionally I added a a missing entry related to the WP embed component implementation.
  • Loading branch information
fluiddot authored Sep 9, 2021
1 parent 96cdb3b commit b1e6865
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/components/src/sandbox/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useState,
useEffect,
} from '@wordpress/element';
import { usePreferredColorScheme } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -162,6 +163,7 @@ function Sandbox( {
type,
url,
} ) {
const colorScheme = usePreferredColorScheme();
const ref = useRef();
const [ height, setHeight ] = useState( 0 );
const [ contentHtml, setContentHtml ] = useState( getHtmlDoc() );
Expand All @@ -171,10 +173,14 @@ function Sandbox( {
windowSize.width >= windowSize.height
);
const wasLandscape = useRef( isLandscape );
// On Android, we need to recreate the WebView when the device rotates, otherwise it disappears.
// For this purpose, the key value used in the WebView will change when the device orientation gets updated.
// On Android, we need to recreate the WebView on any of the following actions, otherwise it disappears:
// - Device rotation
// - Light/dark mode changes
// For this purpose, the key prop used in the WebView will be updated with the value of the actions.
const key = Platform.select( {
android: `${ url }-${ isLandscape ? 'landscape' : 'portrait' }`,
android: `${ url }-${
isLandscape ? 'landscape' : 'portrait'
}-${ colorScheme }`,
ios: url,
} );

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ For each user feature we should also add a importance categorization label to i
-->

## Unreleased
- [**] [Embed block] Implement WP embed preview component [#34004]
- [*] [Embed block] Fix content disappearing on Android when switching light/dark mode [#34207]

## 1.61.0
- [**] Enable embed preview for a list of providers (for now only YouTube and Twitter) [#34446]
Expand Down

0 comments on commit b1e6865

Please sign in to comment.