Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #108 from tgpetrov/master
Browse files Browse the repository at this point in the history
fix: make the plugin androidx compatible
  • Loading branch information
bradmartin authored May 14, 2019
2 parents a534f6d + 8b6d855 commit a3bc140
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cardview.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
radiusProperty,
rippleProperty
} from './cardview-common';
declare let global: any;
const CardViewNamespace = useAndroidX() ? global.androidx.cardview.widget : android.support.v7.widget;
const AppCompatResourcesNamespace = useAndroidX() ? 'androidx.appcompat' : 'android.support.v7.appcompat';

function useAndroidX() {
return global.androidx && global.androidx.cardview;
}
export class CardView extends CardViewCommon {
private _androidViewId: number;
public nativeView;
Expand All @@ -31,7 +37,8 @@ export class CardView extends CardViewCommon {
if (!value) {
this.nativeView.setClickable(false);
} else {
const attr = java.lang.Class.forName('android.support.v7.appcompat.R$attr');
const resourcesUri = AppCompatResourcesNamespace + '.R$attr';
const attr = java.lang.Class.forName(resourcesUri);

// https://developer.android.com/reference/java/lang/Class#getField(java.lang.String)
const field = attr.getField('selectableItemBackground') as java.lang.reflect.Field;
Expand All @@ -51,7 +58,7 @@ export class CardView extends CardViewCommon {
}

public createNativeView() {
return new (android.support.v7.widget as any).CardView(this._context);
return new CardViewNamespace.CardView(this._context);
}

public initNativeView() {
Expand Down

0 comments on commit a3bc140

Please sign in to comment.