Skip to content

Merging Discord's React Native's changes into React Native 0.70 Branch #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5dbe2ef
Discord modifications to ReactNative
adgarcia Apr 23, 2019
fd18630
Undo DCDDisplayLink
vishnevskiy May 16, 2020
e38b41f
Fix timers on proximity state change
Atlante45 Nov 19, 2020
1bd0fbc
Update Android websocket module to expose onOpen callback.
mrkcsc Jun 30, 2021
f35117d
Fix Android build.gradle for facebook#28298
mrkcsc Jul 20, 2021
38fc2d0
Update RNA ImageView to use view clipping for corner rounding on supp…
mrkcsc Aug 13, 2021
a96a8a3
Update RNA ImageView to support forced cached property to fix GIF fli…
mrkcsc Dec 11, 2021
2d9a5ef
Update boost podspec to expose PodToBuild friendly artifact.
mrkcsc Dec 12, 2021
2f7c575
enable internal publishing
denbeigh2000 Jan 27, 2022
161db3d
android: add version-bumping script
denbeigh2000 Jan 27, 2022
2f30a2e
improve version bumping script
denbeigh2000 Jan 27, 2022
a4942ae
Adding ota code
charlesx2013 Feb 14, 2022
e6a810c
remove unnecessary gcp artifact store dep
denbeigh2000 Feb 15, 2022
9520464
[RNA] Add max fling velocity capability to scroll view.
mrkcsc Mar 16, 2022
f418aac
[RNA] Add useSmallCache prop to ReactImageView.
mrkcsc Mar 24, 2022
3affaec
animate switch on value change
Apr 7, 2022
729306b
[RNA] Allow modal component to be edge to edge on Android.
mrkcsc Apr 19, 2022
058b5c2
[RNA] Also enable E2E for older Android API 28
mrkcsc Apr 19, 2022
7f6296a
[RNA] Follow up to 7b566db9c9c0775b7c2a8439c2d596a201e20191 remove sy…
mrkcsc Apr 20, 2022
1961d12
Removing ota code
charlesx2013 May 12, 2022
059e3cc
have clicks working to show keyboard on android 7
AndyG May 11, 2022
dfdfaa2
expose `flush` on RCTWebSocketModule to close all open websockets syn…
nealmanaktola May 25, 2022
a0dbe60
Have codegen script prefer `react-codegen` in NPM
FuegoFro Jun 13, 2022
d6e7dcf
Add a preventClipping prop that prevents a subview from ever being cl…
Jun 22, 2022
03d3cd1
Undo accidental changes
Jun 22, 2022
5ebec16
Fix z index when clipped
Jun 22, 2022
3237558
Merge pull request #18 from discord/ankit/prevent-clipping-android
apkumar Jun 22, 2022
13e0c64
fix clipping issue
Jun 22, 2022
4096310
Comment.
Jun 22, 2022
0d474b5
Ripple radius now applies to corner radius instead of circular radius
Flewp Jun 30, 2022
e0c1d60
Piping new prop: cornerRadius
Flewp Jul 5, 2022
246b98a
using new prop in Java
Flewp Jul 5, 2022
4539323
cleanup
Flewp Jul 5, 2022
5375085
Prop name
Flewp Jul 5, 2022
8ecd05a
changed to check against float
AndyG Aug 18, 2022
c78d434
refactor
AndyG Aug 18, 2022
cd8b835
use parseFloat
AndyG Aug 22, 2022
e9e9b07
Align text
charlesx2013 Aug 29, 2022
9807951
Update CustomLineHeightSpan.java
charlesx2013 Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Libraries/Components/Pressable/useAndroidRippleForView.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type NativeBackgroundProp = $ReadOnly<{|
color: ?number,
borderless: boolean,
rippleRadius: ?number,
rippleCornerRadius: ?number,
|}>;

export type RippleConfig = {|
color?: ColorValue,
borderless?: boolean,
radius?: number,
cornerRadius?: number,
foreground?: boolean,
|};

Expand All @@ -45,7 +47,8 @@ export default function useAndroidRippleForView(
| $ReadOnly<{|nativeBackgroundAndroid: NativeBackgroundProp|}>
| $ReadOnly<{|nativeForegroundAndroid: NativeBackgroundProp|}>,
|}> {
const {color, borderless, radius, foreground} = rippleConfig ?? {};
const {color, borderless, radius, cornerRadius, foreground} =
rippleConfig ?? {};

return useMemo(() => {
if (
Expand All @@ -64,6 +67,7 @@ export default function useAndroidRippleForView(
color: processedColor,
borderless: borderless === true,
rippleRadius: radius,
rippleCornerRadius: cornerRadius,
};

return {
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ type AndroidDrawableRipple = $ReadOnly<{|
color?: ?number,
borderless?: ?boolean,
rippleRadius?: ?number,
rippleCornerRadius?: ?number,
|}>;

type AndroidDrawable = AndroidDrawableThemeAttr | AndroidDrawableRipple;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/WebSocket/RCTSRWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ extern NSString *const RCTSRHTTPResponseErrorKey;
- (void)open;

- (void)close;
- (void)flush;

- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;

// Send a UTF8 String or Data.
Expand Down
9 changes: 8 additions & 1 deletion Libraries/WebSocket/RCTSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ - (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode
[_scheduledRunloops removeObject:@[aRunLoop, mode]];
}

- (void)flush
{
// By queueing an empty block, all blocks queued before
// need to finish executing as this is a serial queue
dispatch_sync(_workQueue, ^{});
}

- (void)close
{
[self closeWithCode:RCTSRStatusCodeNormal reason:nil];
Expand Down Expand Up @@ -1389,7 +1396,7 @@ - (void)safeHandleEvent:(NSStreamEvent)eventCode stream:(NSStream *)aStream
// If we get closed in this state it's probably not clean because we should be sending this when we send messages
[self _performDelegateBlock:^{
if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
[self.delegate webSocket:self didCloseWithCode:RCTSRStatusCodeGoingAway reason:@"Stream end encountered" wasClean:NO];
[self.delegate webSocket:self didCloseWithCode:self->_closeCode reason:self->_closeReason wasClean:NO];
}
}];
}
Expand Down
3 changes: 2 additions & 1 deletion React/Base/RCTDisplayLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#define RCTAssertRunLoop() \
RCTAssert(_runLoop == [NSRunLoop currentRunLoop], @"This method must be called on the CADisplayLink run loop")

@implementation RCTDisplayLink {
@implementation RCTDisplayLink
{
CADisplayLink *_jsDisplayLink;
NSMutableSet<RCTModuleData *> *_frameUpdateObservers;
NSRunLoop *_runLoop;
Expand Down
14 changes: 14 additions & 0 deletions React/CoreModules/RCTTiming.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ - (void)setup
name:name
object:nil];
}

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceProximityStateDidChange)
name:UIDeviceProximityStateDidChangeNotification
object:nil];
}

- (void)dealloc
Expand Down Expand Up @@ -182,6 +187,15 @@ - (void)appDidMoveToForeground
[self startTimers];
}

- (void)deviceProximityStateDidChange
{
if ([[UIDevice currentDevice] proximityState]) {
[self appDidMoveToBackground];
} else {
[self appDidMoveToForeground];
}
}

- (void)stopTimers
{
if (_inBackground) {
Expand Down
3 changes: 3 additions & 0 deletions React/CoreModules/RCTWebSocketModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN

- (void)sendData:(NSData *)data forSocketID:(nonnull NSNumber *)socketID;

// Blocking call that waits until there are no more remaining actions on the queue
- (void)flush;

@end

@interface RCTBridge (RCTWebSocketModule)
Expand Down
10 changes: 8 additions & 2 deletions React/CoreModules/RCTWebSocketModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ - (NSArray *)supportedEvents
return @[ @"websocketMessage", @"websocketOpen", @"websocketFailed", @"websocketClosed" ];
}


- (void)flush
{
for (RCTSRWebSocket *socket in _sockets.allValues) {
[socket flush];
}
}

- (void)invalidate
{
[super invalidate];
Expand Down Expand Up @@ -167,7 +175,6 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
{
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
NSDictionary *body =
@{@"message" : error.localizedDescription ?: @"Undefined, error is nil", @"id" : socketID ?: @(-1)};
[self sendEventWithName:@"websocketFailed" body:body];
Expand All @@ -180,7 +187,6 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket
{
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketClosed"
body:@{
@"code" : @(code),
Expand Down
12 changes: 11 additions & 1 deletion React/Views/RCTSwitchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ - (void)onChange:(RCTSwitch *)sender
RCT_EXPORT_VIEW_PROPERTY(onTintColor, UIColor);
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor);
RCT_EXPORT_VIEW_PROPERTY(thumbTintColor, UIColor);
RCT_REMAP_VIEW_PROPERTY(value, on, BOOL);
//RCT_REMAP_VIEW_PROPERTY(value, on, BOOL);
RCT_CUSTOM_VIEW_PROPERTY(value, BOOL, RCTSwitch)
{
if (json) {
BOOL on = [RCTConvert BOOL:json];
if (view.wasOn != on) {
[(UISwitch *)view setOn:on animated:YES];
view.wasOn = on;
}
}
}
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock);
RCT_CUSTOM_VIEW_PROPERTY(disabled, BOOL, RCTSwitch)
{
Expand Down
17 changes: 15 additions & 2 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,24 @@ task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
dest(new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz"))
}

// A temporary workaround for build failing on some machines.
// See: https://github.com/facebook/react-native/issues/28298
def follyReplaceContent = '''
ssize_t r;
do {
r = open(name, flags, mode);
} while (r == -1 && errno == EINTR);
return r;
'''

task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) {
from(dependenciesPath ?: tarTree(downloadFolly.dest))
from("src/main/jni/third-party/folly/")
include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk", "CMakeLists.txt")
eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
// Fixes problem with Folly failing to build on certain systems.
// See https://github.com/facebook/react-native/issues/28298
filter { line -> line.replaceAll('return int\\(wrapNoInt\\(open, name, flags, mode\\)\\);', follyReplaceContent) }
includeEmptyDirs = false
into("$thirdPartyNdkDir/folly")
}
Expand Down Expand Up @@ -482,8 +495,8 @@ afterEvaluate {

repositories {
maven {
name = "npm"
url = AAR_OUTPUT_URL
name = "discord"
url = uri("gcs://discord-maven")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ public String getName() {

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean getIsReduceMotionEnabledValue() {
String value =
Settings.Global.getString(mContentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE);

return value != null && value.equals("0.0");
float defaultAnimationScale = Float.parseFloat(Settings.Global.TRANSITION_ANIMATION_SCALE);
float animationScale = Settings.Global.getFloat(mContentResolver, defaultAnimationScale);
return animationScale == 0f;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public interface ContentHandler {
void onMessage(ByteString byteString, WritableMap params);
}

public interface OnOpenHandler {

void onOpen(final WebSocket webSocket, final int socketId);
}

public @Nullable OnOpenHandler mOnOpenHandler = null;

private final Map<Integer, WebSocket> mWebSocketConnections = new ConcurrentHashMap<>();
private final Map<Integer, ContentHandler> mContentHandlers = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -154,6 +161,10 @@ public void onOpen(WebSocket webSocket, Response response) {
params.putInt("id", id);
params.putString("protocol", response.header("Sec-WebSocket-Protocol", ""));
sendEvent("websocketOpen", params);

if (mOnOpenHandler != null) {
mOnOpenHandler.onOpen(webSocket, id);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public String getName() {
return REACT_CLASS;
}

@ReactProp(name = "useSmallCache")
public void setUseSmallCache(ReactImageView view, boolean useSmallCache) {
view.setUseSmallCache(useSmallCache);
}

@ReactProp(name = "accessible")
public void setAccessible(ReactImageView view, boolean accessible) {
view.setFocusable(accessible);
Expand Down
Loading