dripsy icon indicating copy to clipboard operation
dripsy copied to clipboard

The linear gradient component crashes the app on expo SDK 45.

Open WillenOLeal opened this issue 2 years ago • 23 comments

Steps to Reproduce:

  1. Create an expo managed app with expo init (SDK 45);
  2. Install dripsy and @dripsy/gradient(3.6.0);
  3. Use the gradient component anywhere on the app.

Sample App.tsx


import { Gradient } from "@dripsy/gradient";
import { DripsyProvider, makeTheme } from "dripsy";
import { StatusBar } from "expo-status-bar";
import { Text } from "react-native";

const theme = makeTheme({...});

export default function App() {
  return (
    <DripsyProvider theme={theme}>
      <Gradient
        colors={["green", "blue"]}
        sx={{ flex: 1, alignItems: "center", justifyContent: "center" }}
      >
        <Text>Open up App.tsx to start working on your app!</Text>
        <StatusBar style="auto" />
      </Gradient>
    </DripsyProvider>
  );
}

Expected Result

The app runs crash free

Actual Result

Screen Shot 2022-05-08 at 8 50 58 PM

Screen Shot 2022-05-08 at 9 04 38 PM

WillenOLeal avatar May 09 '22 01:05 WillenOLeal

did you install expo-linear-gradient

nandorojo avatar May 09 '22 01:05 nandorojo

@nandorojo yep! I have "expo-linear-gradient": "~11.3.0", installed. I also ran expo start -c after it, but no luck.

WillenOLeal avatar May 09 '22 01:05 WillenOLeal

does expo's normal gradient work for you?

nandorojo avatar May 09 '22 01:05 nandorojo

Yes, the expo-linear-gradient works fine (code below). I noticed I am using expo-linear-gradient version 11., however I think that the @dripsy/gradient package is using version 10, could that be the reason?


import { Gradient } from "@dripsy/gradient";
import { DripsyProvider, makeTheme } from "dripsy";
import { LinearGradient } from "expo-linear-gradient";
import { StatusBar } from "expo-status-bar";
import { Text } from "react-native";

const theme = makeTheme({...});

export default function App() {
  return (
    <DripsyProvider theme={theme}>
      <LinearGradient
        colors={["green", "blue"]}
        style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
      >
        <Text>Open up App.tsx to start working on your app!</Text>
        <StatusBar style="auto" />
      </LinearGradient>
    </DripsyProvider>
  );
}

WillenOLeal avatar May 09 '22 01:05 WillenOLeal

oh yeah that’s probably it. try a yarn resolution for now

nandorojo avatar May 09 '22 01:05 nandorojo

Thank you, that did the trick!

Package.json

  "resolutions": {
    "@dripsy/gradient/**/expo-linear-gradient": "~11.3.0",
  },

WillenOLeal avatar May 09 '22 01:05 WillenOLeal

I think just expo-linear-gradient should suffice, but that works too. I’ll make this a peer dep in a future release. Glad that worked!

nandorojo avatar May 09 '22 01:05 nandorojo

Even with the change mentioned above, I still can't get the gradient to show on iOS. I installed @dripsy/gradient on the packages/app directory. It works on web, but not on iOS, any clues? Screen Shot 2022-06-18 at 1 37 12 AM

luizkc avatar Jun 18 '22 05:06 luizkc

did you use the resolution above? i haven’t had time to focus on fixing this internally

nandorojo avatar Jun 18 '22 11:06 nandorojo

Yep, I did use the resolutions above.

luizkc avatar Jun 18 '22 14:06 luizkc

are you using yarn?

nandorojo avatar Jun 18 '22 14:06 nandorojo

Yep. I'm using the Solito Starter Repo with Yarn. This is the package.json inside my packages/app directory:

{
  "version": "0.0.0",
  "name": "app",
  "main": "index.ts",
  "dependencies": {
    "@dripsy/gradient": "^3.6.0",
    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.5.0",
    "dripsy": "^3.6.0",
    "expo-linking": "^3.0.0",
    "firebase": "^9.8.3",
    "moti": "canary",
    "solito": "latest"
  },
  "resolutions": {
    "@dripsy/gradient/**/expo-linear-gradient": "~11.3.0"
  },
  "sideEffects": false
}

luizkc avatar Jun 18 '22 14:06 luizkc

can you put the resolution in the root of the repo and then run yarn from the root?

nandorojo avatar Jun 18 '22 14:06 nandorojo

Tried moving the resolution to the root package.json and the gradient still won't render on iOS.

luizkc avatar Jun 18 '22 14:06 luizkc

try yarn why expo-linear-gradient. does it work if you import direct from expo?

nandorojo avatar Jun 18 '22 14:06 nandorojo

also try removing everything before expo in the resolution

nandorojo avatar Jun 18 '22 14:06 nandorojo

I removed everything before expo in the resolution. yarn why expo-linear-gradient ran successfully from the root dir. However, now the app won't build anymore. These are some of the errors it throws. Any other suggestions?

Screen Shot 2022-06-18 at 11 15 59 AM

luizkc avatar Jun 18 '22 15:06 luizkc

what was the result of yarn why?

nandorojo avatar Jun 18 '22 15:06 nandorojo

i see, if you’re using a custom dev client, the issue is that expo isn’t autolinking to the right place. so you should also expo install expo-linear-gradient in apps/expo. then take the version it installed and use that in your root resolution.

the solito starter also isn’t on SDK 45 (yet), so you need your yarn resolution to match the sdk version you’re on. deoendencies are always the issue…lol

nandorojo avatar Jun 18 '22 15:06 nandorojo

Yarn why results:

Screen Shot 2022-06-18 at 11 30 28 AM

So if I install it in the expo directory, should I also leave it installed in the packages/app directory for next.js to be able to use it as well?

luizkc avatar Jun 18 '22 15:06 luizkc

that’s correct. and you need the versions to match, but a yarn resolution solves that.

nandorojo avatar Jun 18 '22 15:06 nandorojo

I did the below and I'm still not seeing the gradient. Let me know if I did anything wrong or if there's anything else I can try. Thank you for being so helpful!

  • expo-linear-gradient with version 11.0.3 is installed in packages/app and apps/expo
  • a resolution like the below, targeting expo-linear-gradient with the same version is in the package.json in the root. I tried both ways:
// suggestion 1: app builds but no gradient
  "resolutions": {
    "@dripsy/gradient/**/expo-linear-gradient": "~11.3.0"
  },

// suggestion 2: app doesn't build, see the last error message I posted
  "resolutions": {
    "expo-linear-gradient": "~11.3.0"
  },

The first time I run the app using suggestion 1 (on iOS) I see the gradient flash very quickly, less than a second, then it goes away 🤔

luizkc avatar Jun 18 '22 15:06 luizkc

So this is the solution I've gone with for now:

  • Created a Gradient component
  • Gradient/index.web.tsx uses @dripsy/gradient
  • Gradient/index.tsx uses expo-linear-gradient
  • I can't use my <Gradient /> component anywhere in the packages/app/provider directory
  • I can use my <Gradient /> component in almost any other directory and it will render fine on iOS and the web

luizkc avatar Jun 18 '22 16:06 luizkc

Can you try upgrading to 3.7.x for both dripsy and the gradient?

nandorojo avatar Sep 13 '22 22:09 nandorojo