Skip to content

Commit

Permalink
readme and example update (#65)
Browse files Browse the repository at this point in the history
* added getIcon method

if default icon is selected returns "default" else returns selected icon name

* brought try...catch back, removed unused in android part, stored coponentClass... in var

* added example and updated readme for getIcon

* Update README.md
  • Loading branch information
TheKeeroll authored Aug 10, 2022
1 parent 02b5e4f commit c851d99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ protected List<ReactPackage> getPackages() {
Now you can use the following code to change application icon:

```javascript
import { changeIcon } from 'react-native-change-icon';
import { changeIcon, getIcon } from 'react-native-change-icon';

// Pass the name of icon to be enabled
changeIcon('iconname');
```

`changeIcon` function returns a promise. The promise is resolved only when the icon is changed.
//or get currently selected icon
getIcon();
```

`changeIcon` function returns a promise. The promise is resolved only when the icon is changed.\
`getIcon` function returns `Promise<string>` with the name of the selected icon or "default" if default icon is selected
**Please refer to the example app for demo on implementation**
17 changes: 13 additions & 4 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import * as React from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import { changeIcon } from 'react-native-change-icon';
import { changeIcon, getIcon } from 'react-native-change-icon';

export default function App() {
const [currentIconName, setCurrentIconName] = React.useState('')

return (
<View style={styles.container}>
<TouchableOpacity onPress={() => changeIcon('checked')}>
<TouchableOpacity onPress={() => {
changeIcon('checked')
getIcon().then(name=>setCurrentIconName(name))
}}>
<Text style={styles.button}>SWITCH TO CHECKED ICON</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => changeIcon('cancel')}>
<TouchableOpacity onPress={() => {
changeIcon('cancel')
getIcon().then(name=>setCurrentIconName(name))
}}>
<Text style={styles.button}>SWITCH TO CANCEL ICON</Text>
</TouchableOpacity>
<Text>{'Icon name: ' + currentIconName}</Text>
</View>
);
}
Expand All @@ -26,5 +35,5 @@ const styles = StyleSheet.create({
fontSize: 20,
textAlign: 'center',
margin: 10,
},
}
});

0 comments on commit c851d99

Please sign in to comment.