Skip to content
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

Feature/1675 dark mode android integration #1717

Merged
merged 43 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bd548aa
Update gb reference
marecar3 Dec 21, 2019
4a1a2b9
create preferred color scheme bridge method to get android app theme
marecar3 Dec 21, 2019
549cca0
Update release notes
marecar3 Dec 21, 2019
ff9c5fa
Update gb reference
marecar3 Dec 21, 2019
21272a3
Fix failed tests
marecar3 Dec 21, 2019
c946228
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Dec 25, 2019
f49003e
Update gb reference
marecar3 Dec 25, 2019
f86d63e
Update gb reference
marecar3 Dec 25, 2019
3a99499
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Dec 26, 2019
83dcff1
Set preferred color scheme from system settings
marecar3 Dec 26, 2019
a25de0f
Set background color to react root view
marecar3 Dec 26, 2019
5c85940
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Jan 8, 2020
8354f16
Update gb reference
marecar3 Jan 8, 2020
1b3d7f6
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Jan 13, 2020
980e594
Update gb reference
marecar3 Jan 13, 2020
14971cd
Use event instead of callback for preferred color scheme
marecar3 Jan 13, 2020
ed75e17
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Jan 14, 2020
693ed73
update gb reference
marecar3 Jan 14, 2020
d1cb304
propagate link text color from JS
marecar3 Jan 14, 2020
584512f
Update gb reference
marecar3 Jan 14, 2020
e7d4156
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Jan 14, 2020
2c1eaf7
update gb reference
marecar3 Jan 14, 2020
62653d9
fix tests
marecar3 Jan 14, 2020
e9c60ae
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Feb 6, 2020
ed36f46
Fix release notes
marecar3 Feb 6, 2020
f2a56dd
Update gb reference
marecar3 Feb 6, 2020
23ebe85
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Feb 6, 2020
0e42546
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Feb 11, 2020
1942f88
Update gb reference
marecar3 Feb 11, 2020
40e30eb
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Feb 13, 2020
2943771
Update gb reference
marecar3 Feb 13, 2020
855baa6
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Mar 10, 2020
d9f164c
Update gb reference
marecar3 Mar 10, 2020
89c1988
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Mar 11, 2020
8039d4d
Update gb reference
marecar3 Mar 11, 2020
eb2cf38
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Mar 12, 2020
064827b
Update gb reference
marecar3 Mar 12, 2020
4ff2cb4
Set fields final
marecar3 Mar 12, 2020
06d5e59
Update dark mode state when battery saver settings are changed
marecar3 Mar 12, 2020
e5fe193
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Mar 12, 2020
ad09ab0
Update gutenberg reference
marecar3 Mar 12, 2020
7855ec1
Point gb reference to master
marecar3 Mar 19, 2020
047913f
Merge branch 'develop' into feature/1675-dark_mode_android_integration
marecar3 Mar 19, 2020
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
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
1.24.0
------
* New block: Latest Posts
* [Android] Can now scroll post when in landscape orientation with the soft keyboard displayed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be part of release notes as it was removed: https://github.com/wordpress-mobile/gutenberg-mobile/pull/1989/files#diff-a3d054590c32de57d87be233927e755dL3
But for some reason, it was reverted from revert.

* Fix Quote block's left border not being visible in Dark Mode
* Added Starter Page Templates: when you create a new page, we now show you a few templates to get started more quickly.
* Fix crash when pasting HTML content with embeded images on paragraphs
* [Android] Dark Mode

1.23.0
------
Expand Down
11 changes: 10 additions & 1 deletion android/app/src/main/java/com/gutenberg/MainApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gutenberg;

import android.app.Application;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;

Expand Down Expand Up @@ -126,7 +127,8 @@ public void editorDidEmitLog(String message, LogLevel logLevel) {

@Override
public void performRequest(String path, Consumer<String> onSuccess, Consumer<Bundle> onError) {}
});

}, isDarkMode());

return new ReactNativeHost(this) {
@Override
Expand All @@ -153,6 +155,13 @@ protected String getJSMainModuleName() {
};
}

private boolean isDarkMode() {
Configuration configuration = getResources().getConfiguration();
int currentNightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;

return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}

@Override
public ReactNativeHost getReactNativeHost() {
if (mReactNativeHost == null) {
Expand Down
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 28 files
+8 −0 docs/designers-developers/developers/block-api/block-registration.md
+9 −3 docs/designers-developers/glossary.md
+29 −3 package-lock.json
+1 −0 package.json
+8 −1 packages/block-editor/src/components/block-inspector/index.js
+5 −0 packages/block-editor/src/components/block-list/style.scss
+5 −1 packages/block-editor/src/components/link-control/style.scss
+3 −0 packages/block-editor/src/store/actions.js
+1 −0 packages/block-library/src/button/index.js
+2 −2 packages/block-library/src/latest-posts/edit.js
+7 −31 packages/block-library/src/social-links/editor.scss
+1 −1 packages/block-library/src/spacer/edit.js
+6 −0 packages/blocks/CHANGELOG.md
+3 −0 packages/components/src/autocomplete/style.scss
+4 −1 packages/components/src/range-control/index.js
+17 −3 packages/components/src/range-control/rail.js
+6 −1 packages/components/src/range-control/stories/index.js
+19 −0 packages/components/src/range-control/styles/range-control-styles.js
+33 −0 packages/compose/src/hooks/use-preferred-color-scheme/index.android.js
+0 −0 packages/compose/src/hooks/use-preferred-color-scheme/index.ios.js
+5 −2 packages/project-management-automation/lib/add-first-time-contributor-label.js
+7 −3 packages/project-management-automation/lib/add-milestone.js
+5 −2 packages/project-management-automation/lib/assign-fixed-issues.js
+6 −4 packages/project-management-automation/lib/if-not-fork.js
+22 −0 packages/project-management-automation/lib/index.js
+44 −0 storybook/test/__snapshots__/index.js.snap
+1 −0 test/native/setup.js
+1 −0 tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ public void setTextAlign(ReactAztecText view, @Nullable String textAlign) {
}
}

@ReactProp(name = "linkTextColor", customType = "Color")
public void setLinkTextColor(ReactAztecText view, @Nullable Integer color) {
view.setLinkFormatter(new LinkFormatter(view,
new LinkFormatter.LinkStyle(
color, true)
));
}

/* End of the code taken from ReactTextInputManager */

@ReactProp(name = "color", customType = "Color")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.wordpress.mobile.ReactNativeGutenbergBridge;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.wordpress.mobile.WPAndroidGlue.MediaOption;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext mReactContext;
Expand All @@ -35,6 +37,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String EVENT_NAME_FOCUS_TITLE = "setFocusOnTitle";
private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload";
private static final String EVENT_NAME_MEDIA_APPEND = "mediaAppend";
private static final String EVENT_NAME_PREFERRED_COLOR_SCHEME = "preferredColorScheme";

private static final String MAP_KEY_UPDATE_HTML = "html";
private static final String MAP_KEY_UPDATE_TITLE = "title";
Expand All @@ -45,6 +48,8 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS = "progress";
private static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_SERVER_ID = "mediaServerId";

private static final String MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK = "isPreferredColorSchemeDark";

private static final int MEDIA_UPLOAD_STATE_UPLOADING = 1;
private static final int MEDIA_UPLOAD_STATE_SUCCEEDED = 2;
private static final int MEDIA_UPLOAD_STATE_FAILED = 3;
Expand All @@ -57,10 +62,12 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String MEDIA_SOURCE_DEVICE_CAMERA = "DEVICE_CAMERA";
private static final String MEDIA_SOURCE_MEDIA_EDITOR = "MEDIA_EDITOR";

private boolean mIsDarkMode;

public RNReactNativeGutenbergBridgeModule(ReactApplicationContext reactContext,
GutenbergBridgeJS2Parent gutenbergBridgeJS2Parent) {
GutenbergBridgeJS2Parent gutenbergBridgeJS2Parent, boolean isDarkMode) {
super(reactContext);
mIsDarkMode = isDarkMode;
mReactContext = reactContext;
mGutenbergBridgeJS2Parent = gutenbergBridgeJS2Parent;
}
Expand All @@ -70,6 +77,14 @@ public String getName() {
return "RNReactNativeGutenbergBridge";
}


@Override
public Map<String, Object> getConstants() {
final HashMap<String, Object> constants = new HashMap<>();
constants.put("isInitialColorSchemeDark", mIsDarkMode);
return constants;
}

private void emitToJS(String eventName, @Nullable WritableMap data) {
mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
}
Expand Down Expand Up @@ -103,6 +118,12 @@ public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType)
emitToJS(EVENT_NAME_MEDIA_APPEND, writableMap);
}

public void setPreferredColorScheme(boolean isDarkMode) {
WritableMap writableMap = new WritableNativeMap();
writableMap.putBoolean(MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK, isDarkMode);
emitToJS(EVENT_NAME_PREFERRED_COLOR_SCHEME, writableMap);
}

@ReactMethod
public void provideToNative_Html(String html, String title, boolean changed) {
mGutenbergBridgeJS2Parent.responseHtml(title, html, changed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@
import java.util.List;

public class RNReactNativeGutenbergBridgePackage implements ReactPackage {
private GutenbergBridgeJS2Parent mGutenbergBridgeJS2Parent;
private final GutenbergBridgeJS2Parent mGutenbergBridgeJS2Parent;
private final boolean mIsDarkMode;

private RNReactNativeGutenbergBridgeModule mRNReactNativeGutenbergBridgeModule;

public RNReactNativeGutenbergBridgeModule getRNReactNativeGutenbergBridgeModule() {
return mRNReactNativeGutenbergBridgeModule;
}

public RNReactNativeGutenbergBridgePackage(GutenbergBridgeJS2Parent gutenbergBridgeJS2Parent) {
public RNReactNativeGutenbergBridgePackage(GutenbergBridgeJS2Parent gutenbergBridgeJS2Parent,
boolean isDarkMode) {
mGutenbergBridgeJS2Parent = gutenbergBridgeJS2Parent;
mIsDarkMode = isDarkMode;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
mRNReactNativeGutenbergBridgeModule = new RNReactNativeGutenbergBridgeModule(reactContext,
mGutenbergBridgeJS2Parent);
mGutenbergBridgeJS2Parent,
mIsDarkMode);
return Arrays.<NativeModule>asList(mRNReactNativeGutenbergBridgeModule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class WPAndroidGlueCode {

private static OkHttpHeaderInterceptor sAddCookiesInterceptor = new OkHttpHeaderInterceptor();
private static OkHttpClient sOkHttpClient = new OkHttpClient.Builder().addInterceptor(sAddCookiesInterceptor).build();
private boolean mIsDarkMode;

public void onCreate(Context context) {
SoLoader.init(context, /* native exopackage */ false);
Expand Down Expand Up @@ -329,7 +330,7 @@ public void requestMediaEditor(MediaUploadCallback mediaUploadCallback, String m
public void logUserEvent(GutenbergUserEvent event, ReadableMap eventProperties) {
mOnLogGutenbergUserEventListener.onGutenbergUserEvent(event, eventProperties.toHashMap());
}
});
}, mIsDarkMode);

return Arrays.asList(
new MainReactPackage(getMainPackageConfig(getImagePipelineConfig(sOkHttpClient))),
Expand All @@ -353,15 +354,18 @@ private ImagePipelineConfig getImagePipelineConfig(OkHttpClient client) {
@Deprecated
public void onCreateView(Context initContext, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
boolean isNewPost, String localeString, Bundle translations) {
boolean isNewPost, String localeString, Bundle translations, int colorBackground, boolean isDarkMode) {
onCreateView(initContext, htmlModeEnabled, application, isDebug, buildGutenbergFromSource, "post", isNewPost
, localeString, translations);
, localeString, translations, colorBackground, isDarkMode);
}

public void onCreateView(Context initContext, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
String postType, boolean isNewPost, String localeString, Bundle translations) {
String postType, boolean isNewPost, String localeString, Bundle translations,
int colorBackground, boolean isDarkMode) {
mIsDarkMode = isDarkMode;
mReactRootView = new ReactRootView(new MutableContextWrapper(initContext));
mReactRootView.setBackgroundColor(colorBackground);

ReactInstanceManagerBuilder builder =
ReactInstanceManager.builder()
Expand All @@ -375,11 +379,8 @@ public void onCreateView(Context initContext, boolean htmlModeEnabled,
builder.setBundleAssetName("index.android.bundle");
}
mReactInstanceManager = builder.build();
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(ReactContext context) {
mReactContext = context;
}
mReactInstanceManager.addReactInstanceEventListener(context -> {
mReactContext = context;
});
Bundle initialProps = mReactRootView.getAppProperties();
if (initialProps == null) {
Expand All @@ -405,7 +406,9 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
RequestExecutor fetchExecutor,
OnImageFullscreenPreviewListener onImageFullscreenPreviewListener,
OnMediaEditorListener onMediaEditorListener,
OnLogGutenbergUserEventListener onLogGutenbergUserEventListener) {
OnLogGutenbergUserEventListener onLogGutenbergUserEventListener,
boolean isDarkMode) {

MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext();
contextWrapper.setBaseContext(viewGroup.getContext());

Expand All @@ -427,6 +430,10 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
viewGroup.addView(mReactRootView, 0,
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

if (mReactContext != null) {
setPreferredColorScheme(isDarkMode);
}

refocus();
}

Expand Down Expand Up @@ -499,6 +506,14 @@ public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType)
.appendNewMediaBlock(mediaId, mediaUri, mediaType);
}

public void setPreferredColorScheme(boolean isDarkMode) {
if (mIsDarkMode != isDarkMode) {
mIsDarkMode = isDarkMode;
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule()
.setPreferredColorScheme(isDarkMode);
}
}

public void setTitle(String title) {
mTitleInitialized = true;
mTitle = title;
Expand Down
6 changes: 6 additions & 0 deletions react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const isIOS = Platform.OS === 'ios';

const gutenbergBridgeEvents = new NativeEventEmitter( RNReactNativeGutenbergBridge );

export const { isInitialColorSchemeDark } = RNReactNativeGutenbergBridge;

export const mediaSources = {
deviceLibrary: 'DEVICE_MEDIA_LIBRARY',
deviceCamera: 'DEVICE_CAMERA',
Expand Down Expand Up @@ -70,6 +72,10 @@ export function subscribeMediaAppend( callback ) {
return gutenbergBridgeEvents.addListener( 'mediaAppend', callback );
}

export function subscribePreferredColorScheme( callback ) {
return gutenbergBridgeEvents.addListener( 'preferredColorScheme', callback );
}

/**
* Request media picker for the given media source.
*
Expand Down