Skip to content

Commit

Permalink
feat: sdk working on iOS
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Jul 3, 2024
1 parent d74a00e commit 2c93393
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 126 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,42 @@ That's it, you now have Ausweis App SDK configured for your iOS and Android proj

## Usage

You can now import `@animo-id/expo-ausweis-sdk` in your application and use the methods from the SDK.
You can now import `@animo-id/expo-ausweis-sdk` in your application and use the methods from the SDK.

```javascript
import AusweisSdk from '@animo-id/expo-ausweis-sdk'
import { useEffect, useState } from 'react'
import { initializeSdk, sendCommand, addMessageListener } from '@animo-id/expo-ausweis-sdk'


export function App() {
const [isSdkInitialized, setIsSdkInitialized] = useState(false)

// Setup listener
useEffect(
addMessageListener((message) => {
console.log('received message', JSON.stringify(message, null, 2))
}).remove,
[]
)

// Initialize SDK
useEffect(() => {
initializeSdk()
.then(() => setIsSdkInitialized(true))
.catch((e) => {
console.log('error setting up', e)
})
}, [])

// Send command once SDK is initialized
useEffect(() => {
if (!isSdkInitialized) return

sendCommand({ cmd: 'GET_INFO' })
}, [isSdkInitialized])

return null
}
```

## Contributing
Expand Down
28 changes: 28 additions & 0 deletions ausweis-example/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import { StyleSheet, Text, View } from 'react-native'
import { initializeSdk, sendCommand, addMessageListener } from '@animo-id/expo-ausweis-sdk'
import { useEffect, useState } from 'react'

export default function App() {
const [isSdkInitialized, setIsSdkInitialized] = useState(false)

// Setup listener
useEffect(
addMessageListener((message) => {
console.log('received message', JSON.stringify(message, null, 2))
}).remove,
[]
)

// Initialize SDK
useEffect(() => {
initializeSdk()
.then(() => setIsSdkInitialized(true))
.catch((e) => {
console.log('error setting up', e)
})
}, [])

// Send command once SDK is initialized
useEffect(() => {
if (!isSdkInitialized) return

sendCommand({ cmd: 'GET_INFO' })
}, [isSdkInitialized])

return (
<View style={[StyleSheet.absoluteFill, { flex: 1, alignContent: 'center', justifyContent: 'center' }]}>
<Text>Hello</Text>
Expand Down
20 changes: 20 additions & 0 deletions ausweis-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { getDefaultConfig } = require('expo/metro-config');
const path = require('node:path');

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.watchFolders = [
path.resolve(__dirname, '..', 'src')
];

defaultConfig.resolver.extraNodeModules = {
...defaultConfig.resolver,
'@animo-id/expo-ausweis-sdk': path.resolve(__dirname, '..', 'src')
}

defaultConfig.resolver.nodeModulesPaths = [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '..', 'node_modules')
]

module.exports = defaultConfig;
8 changes: 5 additions & 3 deletions ausweis-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"android": "expo run:android",
"ios": "expo run:ios"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@animo-id/expo-ausweis-sdk": "../",
"@react-navigation/native": "^6.0.2",
Expand All @@ -26,5 +23,10 @@
"@types/react": "~18.2.45",
"typescript": "~5.3.3"
},
"expo": {
"autoLinking": {
"nativeModulesDir": ".."
}
},
"private": true
}
91 changes: 0 additions & 91 deletions ausweis-example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ausweis-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"strict": true,
"paths": {
"@/*": ["./*"]
"@/*": ["./*"],
"@animo-id/expo-ausweis-sdk": ["../src"]
}
},
"include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"]
Expand Down
Loading

0 comments on commit 2c93393

Please sign in to comment.