Skip to content

Commit 8af5386

Browse files
committed
Add documentation
1 parent 57a3b43 commit 8af5386

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This repository is a working fork of **facebook/react-native** that adds support
2626
[new-app]: https://reactnative.dev/docs/getting-started
2727
[existing]: https://reactnative.dev/docs/integration-with-existing-apps
2828

29-
You can read more about the macOS implementation in our website - [React Native for Windows + macOS](https://microsoft.github.io/react-native-windows/)
29+
You can read more about the macOS implementation in our website - [React Native for Windows + macOS](https://microsoft.github.io/react-native-windows/). You can read about how we manage this fork in our [docs](docs/) folder.
3030

3131
## Requirements
3232

docs/DiffsWithUpstream.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# How React Native macOS differs from React Native
2+
3+
React Native macOS elected to implement our fork via inline diffs of existing React Native code. This means additions and changes of extra code to support macOS, usually in the same file as the existing iOS or JS implementation.
4+
5+
# Rationale
6+
7+
UIKit (The native iOS framework that React Native's iOS implementation is built off) is quite similar to Appkit (the macOS equivalent) which encourages a lot of code sharing and re-use. We found that to encourage maximum code sharing, the use of preprocessor `#ifdef` blocks was best to modify the existing iOS implementation to compile on macOS. This also aides in merging upstream changes from React Native, as it's easier to compare and update our diffs when they're in the same file than if macOS was in a separate implementation file altogether.
8+
9+
# How do we track diffs?
10+
11+
We track diffs through the use of "diff tags" in code comments. Wherever we add or modify code, we try to add a diff tag to mark the beginning and end of the modified code. The diff tags are designed so that you can easily do a search of the string "[macOS" across the entire repository and collect a list of all of our diffs.
12+
13+
## Diff tag format
14+
15+
- Single Line diff
16+
```
17+
// [macOS]
18+
```
19+
- Single Line diff with comment
20+
```
21+
// [macOS] comment explaining change
22+
```
23+
- Block Diff
24+
```
25+
...
26+
// [macOS
27+
...
28+
// macOS]
29+
...
30+
```
31+
- Block Diff with comment
32+
```
33+
...
34+
// [macOS comment explaining change
35+
...
36+
// macOS]
37+
...
38+
```
39+
- Inline diff
40+
```
41+
/* blah blah blah `RCTUIView` [macOS] blah blah */
42+
```
43+
44+
## Forked files
45+
46+
We try to make changes in the same file where possible. However, we sometimes find the need to make completely new files for macOS only code, or for a parallel implementation to the iOS and Android implementations. For these entirely new files, we find it sufficient to simply add a single line diff tag near the top to show that the _file_ is an addition by React Native macOS.
47+
48+
```
49+
Foo.macos.js
50+
====================
51+
/**
52+
* Copyright notice
53+
*/
54+
55+
// [macOS]
56+
57+
... rest of file
58+
=====================
59+
```
60+
61+
## ifdef blocks
62+
63+
Oftentimes we add a few types of ifdef blocks to React Native's iOS code. We follow a few guidelines to keep these consistent and manageable between merges.
64+
65+
1. ifdef macOS only code
66+
67+
```
68+
#if TARGET_OS_OSX // [macOS
69+
...macOS only code
70+
#endif // macOS]
71+
```
72+
Here, we used the block start and end tags to signify the code inside the ifdef is an _addition_ from React Native macOS.
73+
74+
75+
2. ifdef iOS only code
76+
77+
```
78+
#if !TARGET_OS_OSX // [macOS]
79+
...iOS only code
80+
#endif // [macOS]
81+
```
82+
Here, we used single line diff tags to show that the code inside the tags is the original React Native code (as opposed to an iOS block added by React Native macOS)
83+
84+
85+
3. ifdef between an iOS and macOS block
86+
87+
```
88+
#if !TARGET_OS_OSX // [macOS]
89+
...original iOS only code
90+
#else // [macOS
91+
...macOS only code
92+
#endif // macOS]
93+
```
94+
This case is a mix of the earlier two cases. We use a single line tag for the starting if tag to show that the first block of iOS only code is the original code from React Native. Then, we use block tags with the else/endif to show that the macOS code is an addition by Raect Native macOS.
95+
96+
97+

0 commit comments

Comments
 (0)