-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement resolvePlatformColor on iOS * Add Android implementation * Fix alpha channel on Android
- Loading branch information
Showing
29 changed files
with
390 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.DS_Store | ||
.gradle/ | ||
.idea/ | ||
.npmignore | ||
build/ | ||
gradle/ | ||
gradlew | ||
gradlew.bat | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
buildscript { | ||
if (project == rootProject) { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.2' | ||
} | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
android { | ||
compileSdkVersion safeExtGet('compileSdkVersion', 30) | ||
buildToolsVersion safeExtGet('buildToolsVersion', "30.0.2") | ||
|
||
defaultConfig { | ||
minSdkVersion safeExtGet('minSdkVersion', 18) | ||
targetSdkVersion safeExtGet('targetSdkVersion', 30) | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
repositories { | ||
if (project == rootProject) { | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url "$rootDir/../node_modules/react-native/android" | ||
} | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
dependencies { | ||
//noinspection GradleDynamicVersion | ||
implementation "com.facebook.react:react-native:+" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.klarna.platformcolors" | ||
> | ||
</manifest> |
47 changes: 47 additions & 0 deletions
47
android/src/main/java/com/klarna/platformcolors/PlatformColorsModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.klarna.platformcolors; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.ColorPropConverter; | ||
|
||
public class PlatformColorsModule extends ReactContextBaseJavaModule { | ||
public static final String PLATFORM_COLORS_MODULE = "KLAPlatformColors"; | ||
private static final String LOG_TAG = PlatformColorsModule.class.getSimpleName(); | ||
private final @Nullable ReactApplicationContext appContext; | ||
|
||
/** Default constructor. */ | ||
public PlatformColorsModule(@NonNull final ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
appContext = reactContext; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
@NonNull | ||
public String getName() { | ||
return PLATFORM_COLORS_MODULE; | ||
} | ||
|
||
protected String getHexColor(@Nullable ReadableMap color) { | ||
int resolvedColor = ColorPropConverter.getColor(color, appContext); | ||
String hexColor = Integer.toHexString(resolvedColor); | ||
return "#" + hexColor.substring(2) + hexColor.substring(0, 2); | ||
} | ||
|
||
@ReactMethod | ||
public void resolveColor(@Nullable ReadableMap color, | ||
@NonNull final Promise promise) { | ||
promise.resolve(getHexColor(color)); | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public String resolveColorSync(@Nullable ReadableMap color) { | ||
return getHexColor(color); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
android/src/main/java/com/klarna/platformcolors/PlatformColorsPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.klarna.platformcolors; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("unused") | ||
public class PlatformColorsPackage implements ReactPackage { | ||
@Override | ||
@NonNull | ||
public List<NativeModule> createNativeModules(@NonNull final ReactApplicationContext reactContext) { | ||
return Collections.singletonList(new PlatformColorsModule(reactContext)); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public List<ViewManager> createViewManagers(@NonNull final ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const background: unknown; | ||
export const text: unknown; | ||
export const accent: unknown; | ||
export const contrasted: unknown; | ||
import { OpaqueColorValue } from 'react-native'; | ||
|
||
export const background: OpaqueColorValue; | ||
export const text: OpaqueColorValue; | ||
export const accent: OpaqueColorValue; | ||
export const contrasted: OpaqueColorValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.