Skip to content

Commit

Permalink
feat: add support for lower case restart function, deprecate camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
avishayil committed Jan 31, 2023
1 parent 61943c3 commit c1552e3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
with:
filters: |
android:
- 'android/**'
- 'Example/android/**'
- 'android/*/**'
- 'Example/android/*/**'
ios:
- 'ios/**'
- 'Example/ios/**'
- 'ios/*/**'
- 'Example/ios/*/**'
setup:
name: Setup code and environment needed for building, linting and tests
Expand Down
2 changes: 1 addition & 1 deletion Example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function App(): JSX.Element {
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Section title="Step Zero">
<TouchableOpacity onPress={() => RNRestart.Restart()}>
<TouchableOpacity onPress={() => RNRestart.restart()}>
<View style={styles.restartButton}>
<Text>Restart</Text>
</View>
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ Remember to run `cd ios && pod install` to update files used by Xcode.
import RNRestart from 'react-native-restart'; // Import package from node modules

// Immediately reload the React Native Bundle
RNRestart.Restart();
RNRestart.Restart(); // Deprecated
RNRestart.restart();
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public void Restart() {
ProcessPhoenix.triggerRebirth(getReactApplicationContext());
}

@ReactMethod
public void restart() {
ProcessPhoenix.triggerRebirth(getReactApplicationContext());
}

@Override
public String getName() {
return "RNRestart";
Expand Down
11 changes: 11 additions & 0 deletions ios/Restart.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ - (void)loadBundle
return;
}

RCT_EXPORT_METHOD(restart) {
if ([NSThread isMainThread]) {
[self loadBundle];
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
[self loadBundle];
});
}
return;
}

@end
1 change: 1 addition & 0 deletions src/__mocks__/react-native-restart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export default {
Restart: jest.fn(),
restart: jest.fn(),
};
2 changes: 1 addition & 1 deletion src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import RNRestart from "react-native-restart";

describe("test RNRestart API functions", () => {
it("calls the restart function", () => {
RNRestart.Restart();
RNRestart.restart();
});
});
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { RNRestart } = NativeModules;

type RestartType = {
Restart(): void;
restart(): void;
};

export default RNRestart as RestartType;

0 comments on commit c1552e3

Please sign in to comment.