0

I just want to place this image to the top of the screen with ImageBackground component of React-Native, using this background image resizeMode='contain' (NOT cover) since the image is fit to dimensions now I need to place it on top.

Found some solution like here:- https://stackoverflow.com/a/55674160/21163479

But it doesn't seems to be working.

Here is my code

    import { Text, SafeAreaView, ImageBackground } from 'react-native'
    import React from 'react'
    
    const Login = () => {
      return (
        <SafeAreaView style={[{flex: 1}]}>
          <ImageBackground
            source={require('../assets/img/auth-bg.jpg')}
            resizeMode='contain'
            style={[{
              flex: 1,
              justifyContent: 'flex-start',
              backgroundColor: 'pink'
            }]}
            imageStyle={[{ resizeMode: 'contain', alignSelf: 'flex-start' }]}
          >
            <Text>--CONTENT HERE--</Text>
          </ImageBackground>
        </SafeAreaView>
      )
    }
    
    export default Login

And here how it looks

imagebackground resize mode contain to position the image on top of the screen

1 Answer 1

0

Remove imageStyle from the code.

here is the code:-

import { Text, SafeAreaView, ImageBackground, View } from 'react- 
native'
import React from 'react'
const Login = () => {
return (
<SafeAreaView style={[{ flex: 1 }]}>
  <ImageBackground
    source={require('../assets/img/auth-bg.jpg')}
    resizeMode='contain'
    style={[{
      flex: 1,
      justifyContent: 'flex-start',
      backgroundColor: 'pink'
    }]}>
    <Text>--CONTENT HERE--</Text>
  </ImageBackground>
</SafeAreaView>
)
}
export default Login
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.