Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components inside the Text wont follow the width of the Text when screen Orientation is changed #31171

Open
AlenToma opened this issue Mar 16, 2021 · 3 comments
Labels
Component: Text Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.

Comments

@AlenToma
Copy link

Description

So I implement AdMobBanner and then decided to place is inside the Text component.
Why I did that, Well I have AdMobBanner inside TouchableOpacity component and if I do not place it inside the Text, the user wont be able to click on it.

Now this is not the problem, the problem is that when the screen Orientation is changed the component inside the Text wont follow for some reason.

React Native version:

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz
    Memory: 1.13 GB / 7.92 GB
  Binaries:
    Node: 15.6.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.11 - D:\Projects\NovelManager\node_modules\.bin\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 26, 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.3
      System Images: android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.7.30517.126 (Visual Studio Enterprise 2019)
  Languages:
    Java: 11.0.10 - C:\Program Files\AdoptOpenJDK\jdk-11.0.10.9-hotspot\bin\javac.EXE
    Python: 3.9.1 - C:\Python39\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: ~16.13.1 => 16.13.1
    react-native: ^0.63.4 => 0.63.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

I have create a demo that represent the problem here on snack
To test this you will have to view it on your phone.

This is the code you should look into when you navigate snack

               <Text key={attr["index"]} style={{maxWidth:"100%",minWidth:"100%", backgroundColor:"red", justifyContent:"center"}} onPress={e=> {e.preventDefault() }}>
                      <Banner bannerSize="smartBannerPortrait"
                      />
                    </Text>

Expected Results

The Text component should behave like View and when the screen Orientation is changed its children should also follow the Text component style

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@alentoma/banner

@chrisglein
Copy link

Does this match what you see?

Portrait Landscape
portrait landscape

(running the Snack on phone and then rotating)

Expectation is that it stretches like the red box does, correct?

@AlenToma
Copy link
Author

Yes exactly. It should expand. At least it dose when I place it inside a View

@AlenToma
Copy link
Author

Updates

I was able to have a fix that work with text, And this fix should clearly the problem and why this happened.

When I put Banner inside a View everything work greet but when i put it inside the Text. things go bad.

So I Create enableRefresh inside banner and what it dose is that it reload AdmobBanner when screen Orientation is changed.

Have a look here.

const Banner = ({ bannerSize, enableRefresh }: { enableRefresh?: boolean, bannerSize: 'banner' | 'largeBanner' | 'mediumRectangle' | 'fullBanner' | 'leaderboard' | 'smartBannerPortrait' | 'smartBannerLandscape' }) => {
    const [loading, setLoading] = useState(true);
    const [refresh, setRefresh] = useState(false)
    const globalContext = useContext(AppContext);
    const id = __DEV__ ? testId : productionId;
    const bannerError = (reason: any) => {
        console.log(reason);
        setLoading(false)
    }

    const ref = () => {
        setRefresh(true);
        setLoading(true);
    }

    useEffect(() => {
        if (enableRefresh) {
            Dimensions.addEventListener("change", ref);
            return () => Dimensions.removeEventListener("change", ref);
        }
    }, [])

    useEffect(() => {
        setRefresh(false);
    }, [refresh])

    return (
        <View style={{ width: "98%", alignItems: "center", justifyContent: "center" }}>
            {!refresh ? (<AdMobBanner
                bannerSize={bannerSize}
                adUnitID={id}
                onAdViewDidReceiveAd={() => setLoading(false)}
                servePersonalizedAds={true}
                onDidFailToReceiveAdWithError={bannerError} />
            ) : null}
            {
                loading || refresh ? (<Text style={[Style.tabText, { color: "red" }]}>{globalContext.currentLanguage.loadingAds}</Text>) : null
            }
        </View>
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Text Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.
Projects
None yet
Development

No branches or pull requests

2 participants