Skip to content

Commit

Permalink
Merge pull request #504 from jpudysz/feture/image-background
Browse files Browse the repository at this point in the history
fix: regression image background
  • Loading branch information
jpudysz authored Jan 20, 2025
2 parents 0de09db + 91b61c5 commit 81c3094
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppRegistry } from 'react-native'
import { App } from './App2'
import { App } from './App'
import { name as appName } from './app.json'

AppRegistry.registerComponent(appName, () => App)
17 changes: 6 additions & 11 deletions src/core/createUnistylesImageBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import { passForwardedRef } from './passForwardRef'
import { maybeWarnAboutMultipleUnistyles } from './warn'

export const createUnistylesImageBackground = (Component: typeof ImageBackground) => React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
const storedRef = useRef<ImageBackground | null>(null)
const storedImageRef = useRef<Image | null>(null)

useEffect(() => {
return () => {
if (storedRef.current) {
// @ts-ignore
UnistylesShadowRegistry.remove(storedRef.current)
}

if (!storedImageRef.current) {
if (storedImageRef.current) {
// @ts-ignore
UnistylesShadowRegistry.remove(storedImageRef.current)
}
Expand All @@ -31,11 +25,12 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
<Component
{...props}
ref={ref => {
if (ref) {
storedRef.current = ref
}

passForwardedRef(props, ref, forwardedRef)

return () => {
// @ts-ignore
UnistylesShadowRegistry.remove(ref)
}
}}
imageRef={ref => {
if (ref) {
Expand Down

0 comments on commit 81c3094

Please sign in to comment.