-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add App.tsx to test-turbo-modules.sh
- Loading branch information
Showing
2 changed files
with
122 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { multiply } from 'react-native-by-hand'; | ||
import { Calculator, type BinaryOperator, SafeAddition, ComputationResult } from '../../src'; | ||
|
||
// A Rust object | ||
const calculator = new Calculator(); | ||
// A Rust object implementing the Rust trait BinaryOperator | ||
const addOp = new SafeAddition(); | ||
|
||
// A Typescript class, implementing BinaryOperator | ||
class SafeMultiply implements BinaryOperator { | ||
perform(lhs: bigint, rhs: bigint): bigint { | ||
return lhs * rhs; | ||
} | ||
} | ||
const multOp = new SafeMultiply(); | ||
|
||
// bigints | ||
const three = 3n; | ||
const seven = 7n; | ||
|
||
// Perform the calculation, and to get an object | ||
// representing the computation result. | ||
const computation: ComputationResult = calculator | ||
.calculate(addOp, three, three) | ||
.calculateMore(multOp, seven) | ||
.lastResult()!; | ||
|
||
// Unpack the bigint value into a string. | ||
const result = computation.value.toString(); | ||
|
||
export default function App() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Result: {result}</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters