Skip to content

Commit

Permalink
✨ Add button component
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinmagrez committed Jan 31, 2023
1 parent 0a314a5 commit d85b9de
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@ public SmartwayReactNativeUiModule(ReactApplicationContext reactContext) {
public String getName() {
return NAME;
}


// Example method
// See https://reactnative.dev/docs/native-modules-android
@ReactMethod
public void multiply(double a, double b, Promise promise) {
promise.resolve(a * b);
}
}
4 changes: 4 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf']
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
Expand Down
19 changes: 8 additions & 11 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { multiply } from 'smartway-react-native-ui';
import { StyleSheet, View } from 'react-native';
import { Provider as PaperProvider } from 'react-native-paper';
import { Button } from 'smartway-react-native-ui';

export default function App() {
const [result, setResult] = React.useState<number | undefined>();

React.useEffect(() => {
multiply(3, 7).then(setResult);
}, []);

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
</View>
<PaperProvider>
<View style={styles.container}>
<Button icon="camera" mode="contained">Example</Button>
</View>
</PaperProvider>
);
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
],
"scripts": {
"test": "jest",
"tsc": "tsc --project tsconfig.build.json",
"example": "npm run example"
"tsc": "tsc --project tsconfig.build.json"
},
"keywords": [
"react-native",
Expand Down
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Button } from 'react-native-paper';

export { Button };
23 changes: 2 additions & 21 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
import { NativeModules, Platform } from 'react-native';
import { Button } from './components';

const LINKING_ERROR =
`The package 'smartway-react-native-ui' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

const SmartwayReactNativeUi = NativeModules.SmartwayReactNativeUi
? NativeModules.SmartwayReactNativeUi
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return SmartwayReactNativeUi.multiply(a, b);
}
export { Button };

0 comments on commit d85b9de

Please sign in to comment.