Skip to content

Commit 1501410

Browse files
committed
Add support for mocking files
1 parent 838da3c commit 1501410

File tree

9 files changed

+177
-10
lines changed

9 files changed

+177
-10
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ dist/
6262
# Expo Example prebuild generated files
6363
ExpoExample/android
6464
ExpoExample/ios
65+
66+
# IntelliJ
67+
/.idea

example/babel.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
module.exports = {
22
presets: ['module:metro-react-native-babel-preset'],
3+
plugins: [
4+
[
5+
'module-resolver',
6+
{
7+
root: ['./src'],
8+
extensions: [
9+
'.owl.ts',
10+
'.owl.tsx',
11+
'.owl.js',
12+
'.owl.jsx',
13+
'.ts',
14+
'.tsx',
15+
'.js',
16+
'.jsx',
17+
],
18+
alias: {},
19+
},
20+
],
21+
],
322
};

example/metro.config.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ const extraNodeModules = {
1414
};
1515
const watchFolders = [path.resolve(path.join(__dirname, '..', 'dist'))];
1616

17+
const resolver = {
18+
extraNodeModules: new Proxy(extraNodeModules, {
19+
get: (target, name) =>
20+
name in target
21+
? target[name]
22+
: path.join(process.cwd(), `node_modules/${name}`),
23+
}),
24+
};
25+
26+
if (process.env.OWL_BUILD) {
27+
resolver.sourceExts = [
28+
'owl.ts',
29+
'owl.tsx',
30+
'owl.js',
31+
'owl.jsx',
32+
'ts',
33+
'tsx',
34+
'js',
35+
'jsx',
36+
];
37+
}
38+
1739
module.exports = {
1840
transformer: {
1941
getTransformOptions: async () => ({
@@ -23,13 +45,6 @@ module.exports = {
2345
},
2446
}),
2547
},
26-
resolver: {
27-
extraNodeModules: new Proxy(extraNodeModules, {
28-
get: (target, name) =>
29-
name in target
30-
? target[name]
31-
: path.join(process.cwd(), `node_modules/${name}`),
32-
}),
33-
},
48+
resolver,
3449
watchFolders,
3550
};

example/src/PressMe.button.owl.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
import { Button } from 'react-native';
3+
4+
export const PressMeButton = () => {
5+
return <Button title={'Owl Button'} />;
6+
};

example/src/PressMe.button.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
import { Button } from 'react-native';
3+
4+
export const PressMeButton = () => {
5+
return <Button title={'App Button'} />;
6+
};

example/src/PressMe.tsx

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {
2+
ActivityIndicator,
3+
Pressable,
4+
StyleSheet,
5+
Text,
6+
TextInput,
7+
View,
8+
} from 'react-native';
9+
import React from 'react';
10+
import { PressMeButton } from './PressMe.button';
11+
12+
export const PressMe = () => {
13+
const [text, setText] = React.useState('');
14+
const [isLongPressed, setIsLongPressed] = React.useState(false);
15+
const [isLoading, setIsLoading] = React.useState(false);
16+
const [isLoaded, setIsLoaded] = React.useState(false);
17+
18+
React.useEffect(() => {
19+
if (isLoading) {
20+
setTimeout(() => {
21+
setIsLoading(false);
22+
setIsLoaded(true);
23+
}, 1500);
24+
}
25+
}, [isLoading]);
26+
27+
return (
28+
<View style={styles.header}>
29+
{!isLoaded && !isLoading && (
30+
<Pressable
31+
testID="Pressable"
32+
onPress={() => setIsLoading(true)}
33+
onLongPress={() => setIsLongPressed(true)}
34+
style={styles.button}
35+
>
36+
<Text style={styles.buttonText}>Press Me</Text>
37+
<Text style={styles.buttonArrow}>&#8594;</Text>
38+
</Pressable>
39+
)}
40+
41+
{isLoading && <ActivityIndicator />}
42+
43+
{isLongPressed && !isLoading && !isLoaded && (
44+
<Text style={styles.textLongPressed}>Long Pressed!</Text>
45+
)}
46+
47+
{!isLoading && isLoaded && (
48+
<>
49+
<Text style={styles.textInputLabel}>This is a label *</Text>
50+
51+
<TextInput
52+
testID="TextInput"
53+
placeholder="Type something here"
54+
onChangeText={setText}
55+
value={text}
56+
style={styles.textInput}
57+
/>
58+
59+
<PressMeButton />
60+
</>
61+
)}
62+
</View>
63+
);
64+
};
65+
66+
const styles = StyleSheet.create({
67+
header: {
68+
marginVertical: 35,
69+
},
70+
button: {
71+
flexDirection: 'row',
72+
justifyContent: 'space-between',
73+
alignItems: 'center',
74+
borderWidth: 2,
75+
paddingVertical: 7.5,
76+
paddingHorizontal: 20,
77+
borderRadius: 20,
78+
},
79+
textLongPressed: {
80+
marginTop: 35,
81+
fontSize: 20,
82+
fontStyle: 'italic',
83+
textAlign: 'center',
84+
},
85+
textInputLabel: {
86+
fontWeight: '600',
87+
marginBottom: 5,
88+
paddingHorizontal: 20,
89+
},
90+
textInput: {
91+
borderWidth: 1,
92+
paddingVertical: 12,
93+
paddingHorizontal: 20,
94+
borderRadius: 20,
95+
},
96+
highlight: {
97+
fontWeight: '700',
98+
},
99+
buttonText: {
100+
fontSize: 16,
101+
fontWeight: '600',
102+
},
103+
buttonArrow: {
104+
fontSize: 20,
105+
},
106+
});

lib/cli/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const buildIOS = async (
1515
const buildCommand = config.ios?.buildCommand
1616
? [config.ios?.buildCommand]
1717
: [
18-
`xcodebuild`,
18+
`env OWL_BUILD=1 xcodebuild`,
1919
`-workspace ${config.ios?.workspace}`,
2020
`-scheme ${config.ios?.scheme?.split(' ').join('\\ ')}`,
2121
`-configuration ${config.ios?.configuration}`,

native/android/src/main/java/com/formidable/reactnativeowl/ReactNativeOwlModule.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package com.formidable.reactnativeowl;
22

3+
import android.app.Activity;
4+
import android.view.View;
5+
36
import androidx.annotation.NonNull;
47

58
import com.facebook.react.bridge.ReactApplicationContext;
69
import com.facebook.react.bridge.ReactContextBaseJavaModule;
10+
import com.facebook.react.bridge.UiThreadUtil;
711
import com.facebook.react.module.annotations.ReactModule;
812

913
@ReactModule(name = ReactNativeOwlModule.NAME)
1014
public class ReactNativeOwlModule extends ReactContextBaseJavaModule {
1115
public static final String NAME = "ReactNativeOwl";
1216

17+
private static final int UI_FLAG_IMMERSIVE = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
18+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
19+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
20+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
21+
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
22+
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
23+
1324
public ReactNativeOwlModule(ReactApplicationContext reactContext) {
1425
super(reactContext);
1526
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"watch": "tsc --watch",
2424
"prettier:check": "prettier --check 'lib/**/*.{js,ts,tsx}'",
2525
"prettier:apply": "prettier --write 'lib/**/*.{js,ts,tsx}'",
26-
"test": "yarn jest"
26+
"test": "yarn jest",
27+
"example": "yarn --cwd example"
2728
},
2829
"repository": "https://github.com/FormidableLabs/react-native-owl",
2930
"author": "Emmanouil Konstantinidis <[email protected]>",

0 commit comments

Comments
 (0)