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

Allow to stylise flexboxLayoutManager from XML #621

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
targetSdkVersion = 30
compileSdkVersion = 30

androidGradlePluginVersion = "4.2.0"
androidGradlePluginVersion = '7.4.1'
androidxAnnotationVersion = "1.2.0"
androidxAppCompatVersion = "1.2.0"
androidxCoreVersion = "1.3.2"
Expand All @@ -32,7 +32,7 @@ buildscript {
androidxTestExtVersion = "1.1.2"
androidxTestVersion = "1.3.0"
junitVersion = "4.13.2"
kotlinVersion = "1.4.32"
kotlinVersion = '1.6.21'
materialVersion = "1.3.0"
}

Expand Down
1 change: 1 addition & 0 deletions demo-cat-gallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'com.google.android.flexbox.apps.catgallery'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions demo-cat-gallery/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.flexbox.apps.catgallery">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ class MainActivity : AppCompatActivity() {
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)

val flexboxLayoutManager = FlexboxLayoutManager(this).apply {
flexWrap = FlexWrap.WRAP
flexDirection = FlexDirection.ROW
alignItems = AlignItems.STRETCH
}

val recyclerView: RecyclerView = findViewById(R.id.recyclerview)
recyclerView.apply {
layoutManager = flexboxLayoutManager
findViewById<RecyclerView>(R.id.recyclerview).apply {
adapter = CatAdapter()
}
}
Expand Down
13 changes: 9 additions & 4 deletions demo-cat-gallery/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<androidx.recyclerview.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"
app:flexWrap="wrap"
android:orientation="horizontal"
tools:listitem="@layout/viewholder_cat"
app:alignItems="stretch"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
9 changes: 5 additions & 4 deletions demo-cat-gallery/src/main/res/layout/viewholder_cat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_margin="1dp"
android:contentDescription="@string/content_description_cat_view_holder"/>
android:contentDescription="@string/content_description_cat_view_holder"
android:scaleType="centerCrop"
tools:src="@drawable/cat_2" />
1 change: 1 addition & 0 deletions demo-playground/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'com.google.android.apps.flexbox'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions demo-playground/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.apps.flexbox">
xmlns:tools="http://schemas.android.com/tools">

<uses-sdk tools:overrideLibrary="android.support.v14.preference" />

Expand Down
3 changes: 1 addition & 2 deletions flexbox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "$mavenVersion"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -36,6 +34,7 @@ android {
minifyEnabled false
}
}
namespace 'com.google.android.flexbox'

libraryVariants.all {
it.generateBuildConfigProvider.configure { enabled = false }
Expand Down
4 changes: 1 addition & 3 deletions flexbox/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest
package="com.google.android.flexbox.test"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity android:name=".FlexboxTestActivity"/>
Expand Down
2 changes: 1 addition & 1 deletion flexbox/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest package="com.google.android.flexbox" />
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Parcel;
Expand Down Expand Up @@ -242,6 +243,14 @@ public FlexboxLayoutManager(Context context, @FlexDirection int flexDirection,
*/
public FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.FlexboxLayout, defStyleAttr, 0);
mFlexWrap = a.getInt(R.styleable.FlexboxLayout_flexWrap, FlexWrap.WRAP);
mJustifyContent = a
.getInt(R.styleable.FlexboxLayout_justifyContent, JustifyContent.FLEX_START);
mAlignItems = a.getInt(R.styleable.FlexboxLayout_alignItems, AlignItems.STRETCH);
mMaxLine = a.getInt(R.styleable.FlexboxLayout_maxLine, NOT_SET);
a.recycle();
Properties properties = getProperties(context, attrs, defStyleAttr, defStyleRes);
switch (properties.orientation) {
case LinearLayoutManager.HORIZONTAL:
Expand All @@ -259,8 +268,10 @@ public FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAtt
}
break;
}
setFlexWrap(FlexWrap.WRAP);
setAlignItems(AlignItems.STRETCH);
setFlexWrap(mFlexWrap);
setJustifyContent(mJustifyContent);
setAlignItems(mAlignItems);
setMaxLine(mMaxLine);
mContext = context;
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Sep 09 14:42:19 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Loading