forked from mongodb/docs-realm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into docsp-35850-baseurl-js
- Loading branch information
Showing
14 changed files
with
179 additions
and
25 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
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
8 changes: 8 additions & 0 deletions
8
...es/react-native/v12/TestApp/ios/TestApp.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
24 changes: 24 additions & 0 deletions
24
examples/react-native/v12/TestApp/src/components/app-services/use-app.test.tsx
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,24 @@ | ||
import 'react-native'; | ||
import React from 'react'; | ||
import {AppWithAuthHook} from './use-app'; | ||
import {render, screen, userEvent} from '@testing-library/react-native'; | ||
import '@testing-library/jest-dom'; | ||
|
||
test('App with auth hook', async () => { | ||
render(<AppWithAuthHook />); | ||
|
||
const user = userEvent.setup(); | ||
|
||
const logInButton = screen.queryByTestId('log-in'); | ||
|
||
if (logInButton) { | ||
await user.press(logInButton); | ||
} | ||
|
||
const loggedInUserText = await screen.findByTestId('logged-in-user-id'); | ||
expect(loggedInUserText).not.toEqual(null); | ||
|
||
const notYetLoggedIn = screen.queryByText('No one is logged in yet.'); | ||
|
||
expect(notYetLoggedIn).not.toBeInTheDocument(); | ||
}); |
93 changes: 93 additions & 0 deletions
93
examples/react-native/v12/TestApp/src/components/app-services/use-app.tsx
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,93 @@ | ||
// :snippet-start: app-config-imports | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
// :snippet-end: | ||
// :snippet-start: import-use-app | ||
// :uncomment-start: | ||
//import React from 'react'; | ||
// :uncomment-end: | ||
import {useApp} from '@realm/react'; | ||
// :snippet-end: | ||
import {useAuth} from '@realm/react'; | ||
import {Text, View, Pressable, StyleSheet} from 'react-native'; | ||
import {APP_ID} from '../../../appServicesConfig'; | ||
|
||
// :snippet-start: app-config | ||
export const AppWithAuthHook = () => { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<UserProvider fallback={LogIn}> | ||
<MyApp /> | ||
</UserProvider> | ||
</AppProvider> | ||
</View> | ||
); | ||
}; | ||
// :snippet-end: | ||
|
||
const LogIn = () => { | ||
const {logInWithAnonymous} = useAuth(); | ||
|
||
return ( | ||
<View> | ||
<Text>No one is logged in yet.</Text> | ||
<Pressable | ||
testID="log-in" | ||
style={styles.button} | ||
onPress={logInWithAnonymous}> | ||
<Text style={styles.buttonText}>Log in</Text> | ||
</Pressable> | ||
</View> | ||
); | ||
}; | ||
|
||
// :snippet-start: use-app | ||
function MyApp() { | ||
const app = useApp(); | ||
// Proceed to app logic... | ||
// :remove-start: | ||
return ( | ||
<Text testID="logged-in-user-id">"Logged in as user with ID: {app.currentUser?.id}"</Text> | ||
); | ||
// :remove-end: | ||
} | ||
// :snippet-end: | ||
|
||
const styles = StyleSheet.create({ | ||
section: { | ||
flex: 1, | ||
marginTop: 8, | ||
paddingVertical: 12, | ||
alignItems: 'center', | ||
}, | ||
textInput: { | ||
backgroundColor: '#C5CAE9', | ||
borderBottomWidth: StyleSheet.hairlineWidth, | ||
marginVertical: 5, | ||
}, | ||
inputGroup: { | ||
width: '100%', | ||
}, | ||
buttonGroup: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
marginVertical: 12, | ||
paddingVertical: 8, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
button: { | ||
backgroundColor: '#3F51B5', | ||
borderWidth: StyleSheet.hairlineWidth, | ||
borderColor: '#ffffff', | ||
paddingVertical: 5, | ||
paddingHorizontal: 8, | ||
marginVertical: 5, | ||
marginHorizontal: 8, | ||
}, | ||
buttonText: { | ||
color: '#ffffff', | ||
textAlign: 'center', | ||
}, | ||
}); |
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
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
10 changes: 0 additions & 10 deletions
10
source/examples/generated/react-native/ts/use-app.test.snippet.use-app.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
.../examples/generated/react-native/v12/use-app.snippet.app-config-imports.tsx.rst
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,4 @@ | ||
.. code-block:: typescript | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; |
13 changes: 13 additions & 0 deletions
13
source/examples/generated/react-native/v12/use-app.snippet.app-config.tsx.rst
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,13 @@ | ||
.. code-block:: typescript | ||
export const AppWithAuthHook = () => { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<UserProvider fallback={LogIn}> | ||
<MyApp /> | ||
</UserProvider> | ||
</AppProvider> | ||
</View> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
source/examples/generated/react-native/v12/use-app.snippet.import-use-app.tsx.rst
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,4 @@ | ||
.. code-block:: typescript | ||
import React from 'react'; | ||
import {useApp} from '@realm/react'; |
6 changes: 6 additions & 0 deletions
6
source/examples/generated/react-native/v12/use-app.snippet.use-app.tsx.rst
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,6 @@ | ||
.. code-block:: typescript | ||
function MyApp() { | ||
const app = useApp(); | ||
// Proceed to app logic... | ||
} |
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
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