PRATIK SHARMA
PRATIK SHARMA

Reputation: 11

how to add set as wallpaper feature in my react native app

I am using Expo Go, and I am creating a Wallpaper app I want to set image/wallpaper on the user's Device when the user clicks on the Set as Wallpaper Button I searched the internet and tried many packages, but nothing worked for me

I tried Packages the following packages:

None of these solutions are working for me.

The imports give me the following warning:

Could not find a declaration file for module 'react-native-manage-wallpaper'.
Note: Now its not giving me this warning.

Now This Error is Coming

Error: Type is undefined
import {TYPE} from "react-native-manage-wallpaper
Use TYPE.HOME"

Even though I have Imported it.

Here is my attempt:

const handleSetWallpaper =  () => {
    ManageWallpaper.setWallpaper(
        {
            uri: imageSource,
        },
        TYPE.HOME,
    );
};

Upvotes: 1

Views: 476

Answers (1)

Viraj Shah
Viraj Shah

Reputation: 792

This is an extremely simple problem with an even simpler solution.

Whenever you get a missing declaration error, you should think back to what kind of project you're working with: Vanilla JavaScript or TypeScript.

This kind of error only comes up when you're working on a TypeScript project.

Next, what does it mean to have a missing declaration? You can use JavaScript library in your TypeScript project, but generally, you need typings. Most NPM packages will either be written in TypeScript (so there are no requirements to have a declaration), or they will include the appropriate .d.ts files, so that they can be used in a TypeScript project.

Another alternative is that the package is ignorant towards TypeScript – it is not written in TypeScript, nor does it include any .d.ts files to supplement the JavaScript.

If a package is ignorant towards TypeScript, you can normally find a declaration package in the @types namespace; for example:

yarn add @types/liuhong1happy
# or
npm install --dev @types/liuhong1happy

Note: I have not verified that there are type declaration packages for the packages that you have listed.


If there is no third-party that shared the type declarations for the specific package that you're working with, then you may want to create your own.

Oftentimes by reading the documentation, you can figure out what the class structure, function signatures, etc are. Using this information, you can create your own .d.ts file and write the type declarations yourself – and you only need to include the declarations for the functions/classes that you're using.

Upvotes: 0

Related Questions