Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# When using RN in combination with Cocoapods, a lot of
# things are broken. These are the fixes we had to append
# to our Podfile when upgrading to ReactNative@0.55.3.
#
# WARNING: Check those line numbers when you're on a different version!
def change_lines_in_file(file_path, &change)
print "Fixing #{file_path}...\n"
contents = []
file = File.open(file_path, 'r')
file.each_line do | line |
contents << line
end
file.close
File.open(file_path, 'w') do |f|
f.puts(change.call(contents))
end
end
post_install do |installer|
# https://github.com/facebook/yoga/issues/711#issuecomment-381098373
change_lines_in_file('./Pods/Target Support Files/yoga/yoga-umbrella.h') do |lines|
lines.reject do | line |
[
'#import "Utils.h"',
'#import "YGLayout.h"',
'#import "YGNode.h"',
'#import "YGNodePrint.h"',
'#import "YGStyle.h"',
'#import "Yoga-internal.h"',
].include?(line.strip)
end
end
# https://github.com/facebook/yoga/issues/711#issuecomment-374605785
change_lines_in_file('./node_modules/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h') do |lines|
unless lines[27].include?("#ifdef __cplusplus")
lines.insert(27, "#ifdef __cplusplus")
lines.insert(34, "#endif")
end
lines
end
# https://github.com/facebook/react-native/issues/13198
change_lines_in_file('./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h') do |lines|
lines.map { |line| line.include?("#import <RCTAnimation/RCTValueAnimatedNode.h>") ? '#import "RCTValueAnimatedNode.h"' : line }
end
# https://github.com/facebook/react-native/issues/16039
change_lines_in_file('./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m') do |lines|
lines.map { |line| line.include?("#import <fishhook/fishhook.h>") ? '#import "fishhook.h"' : line }
end
end
@anhtuank7c

This comment has been minimized.

Copy link

commented Apr 24, 2018

You saved my day.
Thank you so much

@MrLaibin

This comment has been minimized.

Copy link

commented May 2, 2018

Thank you so much

@hery

This comment has been minimized.

Copy link

commented May 2, 2018

Wow! I came for the Yoga issues but I'm gonna grab the RCTValueAnimatedNode and fishhook fixes as well, which I've been fixing manually like a goof!

@matteocollina

This comment has been minimized.

Copy link

commented May 8, 2018

Yes! I used a snippet of your code in my Podfile :
https://gist.github.com/matteocollina/fe2a9c3e2a96061ac1a15c0fcf2cbded

@jlyonsmith

This comment has been minimized.

Copy link

commented May 9, 2018

Thanks very much for posting this. It's a nice clean way to apply the patches. Hopefully the RN team will address these issues at some point! 😝

@ibrahimab

This comment has been minimized.

Copy link

commented May 15, 2018

How is it this issue is still plaguing react native... maybe it's time to switch to Flutter :/

@HideOnBushTuT

This comment has been minimized.

Copy link

commented May 18, 2018

thank you very much

@orta

This comment has been minimized.

Copy link

commented May 24, 2018

https://github.com/orta/cocoapods-fix-react-native centralises a lot of these hacks

@kesha-antonov

This comment has been minimized.

Copy link

commented Jul 22, 2018

Thanks!

@drummonda

This comment has been minimized.

Copy link

commented Aug 13, 2018

Wow thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.