Posts

Showing posts with the label React Native

Cancel All Subscriptions And Asyncs In The ComponentWillUnmount Method, How?

Answer : You can use isMounted React pattern to avoid memory leaks here. In your constructor: constructor(props) { super(props); this._isMounted = false; // rest of your code } componentDidMount() { this._isMounted = true; this._isMounted && this.getImage(this.props.item.image); } in your componentWillUnmount componentWillUnmount() { this._isMounted = false; } While in you getImage() async getImage(img) { let imgUri = await Amplify.Storage.get(img) let uri = await CacheManager.get(imgUri).getPath() this._isMounted && this.setState({ image: { uri }, ready: true }) } A recommend approach to use Axios which is based cancellable promise pattern. So you can cancel any network call while unmounting the component with it's cancelToken subscription . Here is resource for Axios Cancellation From the React blog Just set a _isMounted property to true in componentDidMount and set it to false in ...

Android-studio: Unable To Locate Adb

Image
Answer : A couple of days after posting the above solution, the problem returned on my Windows system. Finally after several hours of investigation I think I have another solution for everyone having issues with AVD Manager "Unable to locate adb". I know we have the setting for the SDK in File -> Settings -> Appearance & Behavior -> System Settings -> Android SDK. This it seems is not enough! It appears that Android Studio (at least the new version 4) does not give projects a default SDK, despite the above setting. So, you also (for each project) need to go to File -> Project Structure -> Project Settings -> Project, and select the Project SDK, which is set to [No SDK] by default. If there's nothing in the drop-down box, then select New, select Android SDK, and navigate to your Android SDK location (normally C:\Users[username]\AppData\Local\Android\Sdk on Windows). You will then be able to select the Android API xx Platform. You now sho...

Call Function OnPress React Native

Answer : In you're render you're setting up the handler incorrectly, give this a try; <View> <Icon name='heart' color={this.state.myColor} size= {45} style={{marginLeft:40}} onPress={this.handleClick} /> </View> The syntax you're using would make sense for declaring an anonymous function inline or something but since your handler is defined on the class, you just reference it (not call it) using this.functionName in the props. A little late to the party, but just wanted to leave this here if someone needs it export default class mainScreen extends Component { handleClick = () => { //some code } render() { return( <View> <Button name='someButton' onPress={() => { this.handleClick(); //usual call like vanilla javascript, but uses this operator }} ...

Androidx MutliDex: The Number Of Method References In A .dex File Cannot Exceed 64K

Answer : Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here: android { defaultConfig { ... minSdkVersion 16 targetSdkVersion 28 multiDexEnabled true } ... } dependencies { implementation 'com.android.support:multidex:1.0.3' } If you do not override the Application class, edit your manifest file to set android:name in the tag as follows: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:name="android.support.multidex.MultiDexApplication" > ... </application> </manifest> If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows: ... import androidx.multidex.M...

Adding Border Only To The One Side Of The Component In React Native (iOS)

Answer : Even though borderBottom doesn't work on the Text component, it did work for me on the TextInput component, just set editable to false and set the value to your desired text as so... <TextInput style={styles.textInput} editable={false} value={'My Text'}/> const styles = StyleSheet.create({ textInput: { borderBottomColor: 'black', borderBottomWidth: 1, } }); This isn't currently possible. See the following RN issue: https://github.com/facebook/react-native/issues/29 and this ticket on Product Pains: https://productpains.com/post/react-native/add-borderwidth-left-right-top-bottom-to-textinput-/

Can I Use React-select In React-native?

Answer : You can't use select2 or react-select with react-native, because it's DOM based and so, it will work only in navigator, not in react-native The closest react-native equivalent I've found is react-native-multiple-select, you can find it on github at https://github.com/toystars/react-native-multiple-select or install it with npm i react-native-multiple-select Probably the closest to what you want that comes bundled with React Native is http://facebook.github.io/react-native/docs/picker.html The Picker component will give you a tumbler thing on iOS and a dropdown on Android Alternatively maybe this 3rd party component is closer to what you want: https://github.com/bulenttastan/react-native-list-popover From How to use React native select box