react-native-admob not working in my RN < 57.8 app
I tried :
npm install react-native-admob#next --save
npm install #types/react-native-admob
npm i react-native-admob -S
npm install
react-native link
declare module 'react-native-admob'
updated tools to 28.0.3
import { AdMobBanner } from 'react-native-admob';
export default class Intro extends React.Component {
bannerError(err){
console.log(err)
}
render() {
return (
<Container style={styles.container}>
<ImageBackground style={{width:'100%',height:'100%',}} source= {require('../assets/start1.jpg')}>
<AdMobBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/2934735716"
testDeviceID="EMULATOR"
didFailToReceiveAdWithError={this.bannerError} />
</ImageBackground >
</Container>
);
}
}
Error
Could not find a declaration file for module 'react-native-admob'.
'e:/react/almustaqbal/node_modules/react-native-admob/index.js'
implicitly has an 'any' type. Try npm install
#types/react-native-admob if it exists or add a new declaration
(.d.ts) file containing declare module 'react-native-admob';ts(7016)
After trying numerous times i guess react-native-admob isn't working in RN<57.8
So i found another way working in RN<57.8 is :
react-native-firebase
i found this web for good explanation https://dev-yakuza.github.io/en/react-native/react-native-firebase-admob/
Related
I created a shared-components repo which contains wrapped Material-UI components and are packaged as an NPM module.
The module works fine when installed via the remote package: npm install *name-of-package*, but when I npm link so I can develop locally it crashes saying the theme variables I define are undefined.
Here is my main repo's code:
import { ThemeProvider } from '#mui/material';
import { theme, Button } from 'my-shared-components'; // npm-link'd repo
...
<ThemeProvider theme={theme}>
<Button>Click</Button>. // crash occurs here saying a theme color is undefined
</ThemeProvider>
package.json
dependencies: {
"#mui/material": "^5.0.0-rc.0",
"#mui/styled-engine": "npm:#mui/styled-engine-sc#next",
"#mui/styled-engine-sc": "^5.0.0-rc.0",
...
}
Shared-Component repo code:
import { createTheme } from '#mui/material/styles';
...
export default createTheme(themeObj);
package.json
"peerDependencies": {
"#mui/material": "^5.0.0-rc.0",
"#mui/styled-engine-sc": "^5.0.0-rc.0",
"#mui/styled-engine": "npm:#mui/styled-engine-sc#next",
...
}
Does anyone know why this would work when I do npm install but not when I npm link? Thanks!
In React Native I found two plugins to check if a device (iOS/Android) is jailbroken/rooted:
Jail Monkey
react-native-is-device-rooted
I have firstly tried the npm package react-native-is-device-rooted but it doesn't work and it seems to be outdated. So I tried Jail Monkey, but I get this following error:
The code is:
import JailMonkey from 'jail-monkey'
export default class Welcome extends Component {
render() {
return (
...
<View style={styles.lowerView}>
<CustomButton text={"Jail Monkey"} onPress={() => this.printJailMonkey()}/>
</View>
...
);
}
printJailMonkey = () => {
console.log("Jail Monkey library content: " + JailMonkey.isJailBroken())
}
}
I have checked carefully the manual link of the package (using Xcode, pod install, and so on...). Nothing worked, does someone can help me?
JailMonkey uses Native Modules and thus cannot run in an Expo managed app. You need to eject it to ExpoKit for JailMonkey to work.
Solved but doing manually the linking.
Try following steps for manual linking.
Navigate to root folder in terminal enter commands:
react-native link
cd ios
pod update
react-native-background-task
I want the code to run back in time. I'm trying to use react-native-background-task. But BackgroundTask.define does not start.
import React from 'react'
import { Text } from 'react-native'
import BackgroundTask from 'react-native-background-task'
BackgroundTask.define(() => {
console.log('Hello from a background task')
BackgroundTask.finish()
})
export default class Home extends React.Component {
componentDidMount() {
BackgroundTask.schedule({
period:1
})
}
render() {
return <Text>Hello world</Text>
}
}
this is due to linking issue
Android
he linking of the library can be done automatically by running:
$ react-native link react-native-background-task
One manual step is still needed -
in your project file android/app/src/main/java/myapp/MainApplication.java, add the following to the end of the onCreate() method:
BackgroundTaskPackage.useContext(this);
iOS
For iOS support, this library relies on version 2.0.x of react-native-background-fetch which can be installed as follows:
$ npm install react-native-background-fetch#2.0.x --save
$ react-native link react-native-background-fetch
This library will behave correctly on iOS as long as react-native-background-fetch is installed alongside it, and has been linked with your project.
I create a new project in react-native ,then install (npm install --save react-navigation npm install --save react-native-gesture-handler),
the latest version (react-native: 0.60.0) auto linking so,I not link ,but still is showing error,
!https://prnt.sc/oaxxuc
Task :react-native-gesture-handler:compileDebugJavaWithJavac **FAILED**
After I uninstall gesture-handler this kind of error showing
!https://prnt.sc/oaxx8i
Please help to solve this error
The react-native latest version:-
System:
OS: Linux 4.15 Ubuntu 16.04.5 LTS (Xenial Xerus)
react: 16.8.6 => 16.8.6
react-native: 0.60.0 => 0.60.0 npmGlobalPackages:
react-native-cli: 2.0.1
thanks
You should paste import 'react-native-gesture-handler'; on the top of index.js which is standard in react native out of the box.
the entry of your app. This is the file where you import your App.js file, its written clearly in the documentations.
documents here https://reactnavigation.org/docs/en/getting-started.html
This issue has been posted on github and you can apply the following solution.
It will work for the RN 0.60.0.
https://github.com/kmagiera/react-native-gesture-handler/issues/642#issuecomment-509113481
First, install the library using yarn:
yarn add react-native-gesture-handler
or with npm if you prefer:
npm install --save react-native-gesture-handler
Linking
react-native link react-native-gesture-handler
Android
Follow the steps below:
If you use one of the native navigation libraries (e.g. wix/react-native-navigation), you should follow this separate guide to get gesture handler library set up on Android. Ignore the rest of this step – it only applies to RN apps that use a standard Android project layout.
Update your MainActivity.java file (or wherever you create an instance of ReactActivityDelegate), so that it overrides the method responsible for creating ReactRootView instance and then use the root view wrapper provided by this library. Do not forget to import ReactActivityDelegate, ReactRootView, and RNGestureHandlerEnabledRootView:
package com.swmansion.gesturehandler.react.example;
import com.facebook.react.ReactActivity;
+ import com.facebook.react.ReactActivityDelegate;
+ import com.facebook.react.ReactRootView;
+ import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
#Override
protected String getMainComponentName() {
return "Example";
}
+ #Override
+ protected ReactActivityDelegate createReactActivityDelegate() {
+ return new ReactActivityDelegate(this, getMainComponentName()) {
+ #Override
+ protected ReactRootView createRootView() {
+ return new RNGestureHandlerEnabledRootView(MainActivity.this);
+ }
+ };
+ }
}
iOS
There is no additional configuration required on iOS except what follows in the next steps.
Now you're all set. Run your app with react-native run-android or react-native run-ios
If you're on React Native >= 0.60, you need to disable autolinking for react-native-gesture-handler first. To disable autolinking for it, create a react-native.config.js file in the root of your project with the following content:
module.exports = {
dependencies: {
'react-native-gesture-handler': {
platforms: {
android: null,
ios: null,
},
},
},
};
As suggested by documentation
On Android RNGH does not work by default because modals are not located under React Native Root view in native hierarchy. To fix that, components need to be wrapped with gestureHandlerRootHOC
const ExampleWithHoc = gestureHandlerRootHOC(() => (
<View>
<DraggableBox />
</View>
);
);
export default function Example() {
return (
<Modal>
<ExampleWithHoc />
</Modal>
);
}
Here the documentation
for react-native-gesture-handle 2 version onwards we just need to following changes at App.js
import {GestureHandlerRootView} from 'react-native-gesture-handler';
export default function App() {
return <GestureHandlerRootView style={{ flex: 1 }}>{/* content */}</GestureHandlerRootView>;
}
Downgrade from 1.1.0 -> 1.0.16 and use exact version(-E):
npm i react-native-gesture-handler#1.0.16 -D -E
I am getting the following error in react native - fontFamily "ionicons" is not a system font and has not been loaded through Font.loadAsync.
If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.
I am trying to import the expo vector icons.
import { Ionicons } from '#expo/vector-icons';
and using the icon
<Button transparent>
<Ionicons name="md-checkmark-circle" size={32} color="green" />
</Button>
but getting the above mentioned error.
Another possible solution I happened upon after of hours of looking at code that should work and which is identical to the sample and the excellent previous answer.
If you have been upgrading Expo this may be your answer.
Delete node_modules
Delete package-lock.json
run expo install
run expo start -c
If nuking node_modules is not working, then make sure you don't have installed multiple versions of expo-font.
Remove expo-font from node_modules/expo/node_modules/expo-font/.
Remove expo-font form list of dependencies from node_modules/expo/package.json.
Run expo r -c
For details Expo cannot load a font due to multiple versions of expo-font installed.
The library #expo/vector-icons is only installed by default on the template project that get through expo init -- it is part of the expo package .
If you created your project using react-native init use react-native-vector-icons instead
Installation
npm i react-native-vector-icons
react-native link react-native-vector-icons
Usage
import Icon from 'react-native-vector-icons/Ionicons';
<Button transparent>
<Icon name="md-checkmark-circle" size={32} color="green" />
</Button>
OR
try loading Ionicons using Font.loadAsync in your App.js
async componentDidMount () {
await Expo.Font.loadAsync({
Ionicons: require('#expo/vector-icons/fonts/Ionicons.ttf'),
});
Adding Iconicons in loadAsync solved this bug for me.
async componentDidMount () {
await Expo.Font.loadAsync({
Ionicons: require('#expo/vector-icons/fonts/Ionicons.ttf'),
});
I solved this problem by removing <Icon\> tag in my code.
After leaving only <Ionicons\> tags for icons, I got saved.
I have fixed this issue by expo upgrade just in case anyone else would see that.
Remove expo-font from package.json.
delete node_modules and package.lock.json .
Run npm install or yarn install
Run npm start or yarn start.
None of the suggestions worked for me. I found the ionicons.ttf file here, downloaded and copied it to my fonts folder and linked it this way:
let [fontsLoaded] = useFonts({
'Ionicons': require('./assets/fonts/ionicons.ttf'),
});
if (!fontsLoaded) {
return ( ... );
} else {
return ( ... )
}
Hope this helps someone.